Adrian Martinez Adrian Martinez - 10 days ago 6
Swift Question

Xcode8 'Could not load NIB in bundle'

Since I have upgraded my project to xcode8 and swift3 I am having troubles when running my app on ios10 devices and simulators.

I can start the app normally but after a while using it I get the following error:

*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:
'NSBundle </Users/****/Library/Developer/CoreSimulator/Devices/****/data/Containers/Bundle/Application/****/*****.app> (loaded)'
with name 'Ncx-Ud-4zl-view-1i6-0r-ivc' and directory 'Main.storyboardc''
***


The strange thing is that I can navigate through the same menu or view sometimes and after 3 or 4 times it gives me the error.

The app works properly on ios9 devices.

Update:
I finally solved it updating my CoreDataStackManager class to the Swift3 sintax and also avoiding using caches on my NSFetchedResultsControllers.

Answer

I've also been struggling with this exact same issue all week where the NIB would sometimes not load randomly. I stumbled across something interesting today that solved my issue though:

(NSFetchedResultsController): couldn't read cache file to update store info timestamps (Thanks Donnit for the answer!)

In short, the problem was to do with the NSFetchResultsController which I use to retrieve and display CoreData models. If you are you using an NSFetchRequestController in your app and you have set your own cacheName inside the initialisation function, it seems a bug introduced by Apple in iOS 10 would open files in the background of the device every time the managed object context was saved. The max number of files an iOS device can open is 255 and so it can't open and load the new NIB files, and then crashes (which seems to be what we're getting).

Donnit has done some testing which shows that this is resolved in beta for iOS 10.2, but a temporary fix for this in the meantime until the update is publicly launched is to remove the cacheName from your NSFetchResultsController's.

Not sure if you have the same issue but it fixed everything for me.

Comments