-1

I have this function in a class that inherits from NSObject:

open func showCustomDialogInView(vc: UIViewController) {
    let bundle = Bundle(for: CustomDialogViewController.self)
    let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle)
    customDialog.delegate = vc
    customDialog.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
    vc.present(customDialog, animated: true, completion: nil)
}

I had this working in one of my iOS projects before updating to Xcode 8 and Swift 3 language, but now when I run the app I get a crash when vc.present(customDialog, animated: true, completion: nil) line is reached. I get this message in log console:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle /MyApp.app> (loaded)' with name 'CustomDialogViewController''

I don't understand what it is happening, since let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle) line doesn't crash and it seems that I get a CustomDialogViewController object.

Does somebody could help me with this issue? Thanks

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
AppsDev
  • 12,319
  • 23
  • 93
  • 186

2 Answers2

0

This error can occur when you rename files outside of XCode. To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference").

Then after you can re-import the files in your project and everything will be OK.

Annie Gupta
  • 2,786
  • 15
  • 23
0

It looks like in this case this error was because for some reason the xib file was missing the appropriate target membership.

Thanks for your answers

AppsDev
  • 12,319
  • 23
  • 93
  • 186