Search code examples
iosswiftuistoryboardnsbundle

Could not load NIB in bundle with name: '5JK-D5-ZKP-view-1nz-4p-isc'


I have a storyboard and it has 2 view controllers including UINavigationController itself. I did some changes in the application and that bug strangely came up.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/***/Library/Developer/CoreSimulator/Devices/96021E81-BD05-4193-86ED-7F386739B99E/data/Containers/Bundle/Application/E684814B-7F84-41CE-B762-64C66A4AE4F8/***.app> (loaded)' with name '5JK-D5-ZKP-view-1nz-4p-isc''

I tried disabling Size Classes, did not work. I also dived into exploring the storyboards XML, found out that 5JK-D5-ZKP is the segue of root view controller found in navigation controller, and 1nz-4p-isc is the table view inside the UITableViewController, which is root view controller.


Solution

  • The reason of the problem was there was a custom initialization in UITableViewController subclass with its method init(coder aDecoder: NSCoder). Being no additional initialization method overridden there, that override was roughly resembling this:

    required init?(coder aDecoder: NSCoder) {
        //  Initialize fetcher
        fetcher = QuestionFetcher(delegate: self)
    
        //  Call the super.init method
        super.init(coder: aDecoder)
    
        //  Initialize the activity indicator for fetching questions
        activityIndicator = UIActivityIndicatorView(frame: CGRect(x: tableView.frame.size.width / 2.00, y: tableView.frame.size.height / 2.00, width: 20, height: 20))
        activityIndicator.hidesWhenStopped = true
        activityIndicator.hidden = true
    }
    

    What's tricky there is, the reader of the signature found in the storyboard tries to call init?(coder: NSCoder) found in the override, however as you see, it is a failable initializer. But that view controller was not loading from a coder, so it failed.