Added new target: Could not load NIB in bundle (NSInternalInconsistencyException) - ios

I'm attempting to add a new build target in Xcode, and so far everything has been going fine - or I've at least been able to figure out why stuff was breaking/not compiling.
Now however, I'm stuck. When building and starting the app using the new target, the app fails with this:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'Valider1''
* First throw call stack:
(0x2f71be83 0x39a7c6c7 0x2f71bdc5 0x321ff391 0x321610fb 0x31fc2b59 0x31ea479d 0x31f4f895 0x31f4f7ab 0x31f4ed89 0x31f4eab1 0x31f4e821 0x31f4e7b9 0x31ea0353 0x31b26943 0x31b22167 0x31b21ff9 0x31b21a0d 0x31b2181f 0x31f1fa3b 0x31f0aedf 0x31ea5a07 0x31ea4cfd 0x31f0a321 0x3438476d 0x34384357 0x2f6e6777 0x2f6e6713 0x2f6e4edf 0x2f64f471 0x2f64f253 0x31f095c3 0x31f04845 0xcd059 0x39f75ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
Now, I've searched for 2 hours regarding this, and theres a lot of results with suggestions, but none of them has solved the problem in my case.
The original build target works perfectly, and I'm using the same app delegate file for both targets.
Here's what I've tried so far:
Tried simulator/real device
Double checked that the "Valider1" is in "Compile sources"
Double checked that "Copy bundle resources" contains my "MainWindow.xib" (this is the nib used for "Valider1"
Double checked that "Valider1" is written correctly everywhere
Cleaned project 100 times
Validated that the Valider.m and "MainWindow.xib" has the new target checked in target membership
.plist files, build settings etc. is all identical to the original and working target
Please SO, tell me what I've done wrong or missed!
edit:
I call my nib like this:
Valider1 *validerVC = [[Valider1 alloc] initWithNibName:#"Valider1" bundle:nil mode:ny_mode];
validerVC.delegate = self;
and it works perfectly when using the original target.
EDIT 2:
I tried with another nib from my project, but still same error.
It would appear that the nibs are not being copied to the new target app, but I have no idea why :/

Remove and re-add the .xib file to Copy Bundle Resources
Go to your project settings.
Select your target.
Click on Build Phases.
Scroll down to Copy Bundle Resources and expand that section.
Check if your .xib file is present in this list -> then remove it.
Now re-add your .xib file by clicking the plus-button and find the file.
It helped me, I hope it helps you as well!

Related

Cannot load xib from framework

I can't seem to load a nib file in the framework I have created. The thing is I worked on it for more than a month and it was working fine. I opened it again today after 2 weeks and it's just crashing. I couldn't believe it.
I have created a tiny sample project where I am able to reproduce the issue.
To get the Bundle I am using
let bundle = Bundle(identifier: "com.nibFramework.NibFramework")
This is returning nil btw.
So I tried
let bundle = Bundle(for: MyNib.self)
Using the nib
let nib = UINib(nibName: "\(MyNib.self)", bundle: bundle)
let array = nib.instantiate(withOwner: self, options: nil)
And this is crashing on instantiate.
Error
2021-11-23 23:55:52.381944+0530 NibApp[7432:2147418] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/7817FD25-54BC-4920-AC67-49D246D28794/NibApp.app> (loaded)' with name 'MyNib''
*** First throw call stack:
(0x1827f904c 0x19ae6df54 0x182850180 0x18513f338 0x1040b0d9c 0x1040af164 0x1040af1c0 0x184db415c 0x184db6c10 0x184d896a4 0x184ecc4d8 0x184e21da0 0x184eb8f84 0x184ed3598 0x184c594a0 0x184f5f584 0x185260400 0x184f61c80 0x184ea10b4 0x1942f0e20 0x194316cdc 0x1942d16b4 0x1942d2cf4 0x10441e3b4 0x104421e70 0x1942d2f94 0x1942d23d4 0x1942d69e4 0x18281b020 0x18282bce0 0x182766054 0x18276b7f4 0x18277f3b8 0x19e10f38c 0x18511f6a8 0x184e9e7f4 0x199e98184 0x1040afcb8 0x1040afc40 0x1040afd38 0x104325a24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/7817FD25-54BC-4920-AC67-49D246D28794/NibApp.app> (loaded)' with name 'MyNib''
terminating with uncaught exception of type NSException
I am using Xcode 13.1. The Mach-O Type of this framework is set to Static Library.
Pretty sure I am missing some simple thing. Just can't figure out what. Thanks for your help.
Any Framework Bundle created with Xcodes Template will have a structure that you can rely on when looking for content packed in it.
Nib/Xib files are Resources, so with compiling they end up being copied into the according subfolder of the created Bundle (Framework in this case).
So you should be able to construct the needed Resources Folder manually.
NSString *privateFWPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *nibPath = [privateFWPath stringByAppendingString:#"/NibFramework.framework/Versions/A/Resources/MyNib"];
another way is to ask the class for its bundle and construct the frameworks Resources folder to reach the nib.
[NSBundle bundleForClass:MyNib.class];
PS: guessing MyNib.self is not a class, it is an object.
A way to check if the nib/xib ended up in the framework is to climb thru the folder structure with your desktops Finder.app. Your App will have a Frameworks folder, in there a NibFramework.framework and in this some link to Resources deeper into the structure or directly a Versions folder, subfolder A in which a Resources folder should be found and the nib will reside in. To do this you will compile first of course and then select the Product in your Xcode project, right click > show in Finder and then right click > Show Contents.
Hint: Asking Bundle for contents has a side effect when the input given results in (nil) or (null), it usually returns the mainBundle then.
Reminder: nib/xib/storyboard files do not reside in the root folder of a bundle.

Xcode 11 Could not find a storyboard named 'Main' in bundle NSBundle

This question has been asked before, but my issue is specifically with Xcode 11 and UISceneConfiguration. Before Xcode 11, when you deleted a storyboard (Main.storyboard) from your target, then added a new one (AnotherStoryboard.storyboard), you would have to update Targets > General > Deployment Info > Main Interface to use your newly added storyboard. In Xcode 11, this is not sufficient and the app will throw an exception
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Could not find a storyboard named 'Main' in bundle NSBundle
The problem I found was that in Info.plist, there is now a new key titled UIApplicationSceneManifest that has a nested UISceneStoryboardFile in it that is being updated when you change the Main Interface within the target. However, there is still a UIMainStoryboardFile key at the top level of Info.plist that is holding the title of the old "Main" storyboard. Long story short, if you delete UIMainStoryboardFile, the app will run fine.
My question: Is this a bug in Xcode 11 or is there something else I'm missing that would prevent this? I didn't really find anything useful while I was trying to debug it and ended up figuring it out on my own.
In your info.plist Main file is set in Scene Configuration, So it always find that file and throw an exception. You can set your default ViewController programatically. In your info.plist set Scene Configuration to Default configuration and Select none into Targets > General > Deployment Info > Main Interface.
Your sceneWillConnectTo be like
window = UIWindow(frame: UIScreen.main.bounds)
window!.windowScene = windowScene
window!.rootViewController = //your homeVC
window!.makeKeyAndVisible()
In your info.plist you have to set this property
Application Scene Manifest -> Scene Configuration -> Application Session Role -> Item 0 -> Storyboard Name
Info.plist

Could not load NIB in bundle :NSBundle

I am trying to load a nib file from MainViewController but i get an exception which i mentioned below. I am not getting this exception regularly (1 out of fifty times). Check the exception below
Exception :
Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/38ABE26C-F87E-49F1-9F29-E46E7ACDBD54/E2_IOS_App.app> (loaded)' with name 'NetWorkError'
the code i use to present this nib file is
NetWorkError *error=[[NetWorkError alloc]initWithNibName:#"NetWorkError" bundle:nil];
error.errorMessage=[details serverDownMessage]; // passing some message before presenting .
[self presentViewController:error animated:YES completion:nil];
i am using an iPad running with iOS 7.
People with similar issues where asked to check the nib name , check if the .xib is added to target, check if the .xib is added to copy bundle resource.But every thing is correct for me. what else might be the issue ??.
Have you tried NSStringFromClass([NetWorkError class]) ?
Also you can try to exclude and add file to your project again / clean project / delete app from simulator.

Main.storyboard not found

I have been trying to figure out solution to the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle
<../Library/Application Support/iPhone Simulator/7.1/Applications/FA7AFF8D-48A6-4C4D- AE92-B15CF6641C4B/myApp.app> (loaded)'
*** First throw call stack:
Tried all possible solutions given in stack overflow. Nothing worked!!
Thanks for any help!
in your Info.plist file find "Main storyboard file base name" and change value for your storyboard's name example "MainStoryboard"
Go to Build Phases -> project target -> Copy Bundle Resources -> + -> Add storyboard here.If it is there than delete and add.
Clean project and Build and run

Can't load sub-view class and xib from static library and bundle

I have 2 iOS projects. Let's call them A and B. A is library project including 2 products:
a static library
and bundle file has some .xib files
B is an app project using project A's library and bundle files.
Project A has 2 things: a table (customized UIViewController class and a .xib file) and a cell (customized UITableViewCell and .xib file)
The problem is:
Project B can load the table from library and bundle, but can't load cell for that table.
This is an open-source project, I am stuck for a few days, please help me out.
https://github.com/G3Feng/granpost-ios
Error:
2013-09-18 07:28:50.184 TabbedDemo[34408:c07] |cell| load bundle:NSBundle </Users/Feng/Library/Application Support/iPhone Simulator/6.1/Applications/359F9352-F3BA-4478-AA51-A182D8CFA4AA/TabbedDemo.app/GPResource.bundle> (not yet loaded)
2013-09-18 07:28:50.185 TabbedDemo[34408:c07] Unknown class articleListCell in Interface Builder file.
2013-09-18 07:28:50.204 TabbedDemo[34408:c07] Could not load the "commentbubble-01.png" image referenced from a nib in the bundle with identifier "(null)"
2013-09-18 07:28:50.206 TabbedDemo[34408:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x71598b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key bottomBar.'
*** First throw call stack:
(0x1c97012 0x10d4e7e 0x1d1ffb1 0xb80e41 0xb025f8 0xb020e7 0x68f23 0xb2cb58 0x236019 0x10e8663 0x1c9245a 0x234b1c 0x2368da 0x39a0 0xd38fb 0xd39cf 0xbc1bb 0xccb4b 0x692dd 0x10e86b0 0x2293fc0 0x228833c 0x2288150 0x22060bc 0x2207227 0x22a9b50 0x2eedf 0x1c5fafe 0x1c5fa3d 0x1c3d7c2 0x1c3cf44 0x1c3ce1b 0x1bf17e3 0x1bf1668 0x18ffc 0x2b1d 0x2a45)
libc++abi.dylib: terminate called throwing an exception
This one solved the problem finally: https://stackoverflow.com/a/6092090/1571946
==>
This doesn't really have anything to do with Interface Builder, what's happening here is the symbols aren't being loaded from your static library by Xcode.
To resolve this problem you need to add the -all_load -ObjC flags to the Other Linker Flags key the Project (and possibly the Target) in the Build Settings.
Check every time you access a resource from another bundle. Try this code.
NSBundle *yourBundleObject = [NSBundle bundleWithIdentifier:#"yourBundleIdentifier"];
if(![yourBundleObject isLoaded]){
[yourBundleObject load];
}

Resources