I am creating a static iOS framework (default template in Xcode 6) that includes xib files.
However I am having trouble loading the nib files when adding my framework to another app, I'm getting the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/89B7C8F1-698A-4E0B-AD8F-4DB414A6001B/Sample.app> (loaded)' with name 'MyNibName''
I have tried several solutions, some outlined here. I still could not resolve the issue.
I see a lot of references to this popular project which is now unsupported because xcode has the built in feature. Should I be using this instead?
In my framework target I have the xib files included in the 'Copy Bundle Resources' build phase and I see them inside the built framework directory, however, I noticed that the structure of the framework produced does not follow the structure outlined in apple's documentation. Even when I changed the framework structure (using versions and linking the Header
and Resources
folders to the current version) I still couldn't resolve the issue.
I tried loading my nib in the following ways:
1 loading the bundle by framework name, the bundle is nil
in this case
NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"myframework" ofType:@"framework"];
resourcesBundle = [NSBundle bundleWithPath:resourceBundlePath];
self = [super initWithNibName:@"MyNibName" bundle:resourcesBundle];
2 Creating a resource bundle and adding it to the framework. Also is nil
. Note that this solution works if I add the bundle to the project separately, but that defeats the purpose of the framework.
NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"resources" ofType:@"bundle"];
resourcesBundle = [NSBundle bundleWithPath:resourceBundlePath];
self = [super initWithNibName:@"MyNibName" bundle:resourcesBundle];
3 Loading bundle by class, still did not work, however it returns the same app bundle as in [NSBundle mainBundle]
. The FrameworkClass
is any class embedded in the framework.
NSBundle* bundle = [NSBundle bundleForClass:[FrameWorkClass class]];
4 Loading the main bundle with [NSBundle mainBundle]
which doesnt and shouldnt work.
I think what is happening is that the resources of the framework are not being included in the final app.
What am I missing? has anyone been able to use the default static framework template in xcode to make a framework with nib files?
This should load your bundle.
Swift
let frameworkBundleID = "com.framework.bundleId";
let bundle = Bundle(identifier: frameworkBundleID)
Objective C
NSString* const frameworkBundleID = @"com.framework.bundleId";
NSBundle* bundle = [NSBundle bundleWithIdentifier:frameworkBundleID];