1
votes

I just wrote a cocoapod and published it. Locally, it works just fine with the example.

However, when I try to install it through 'pod install' and use it, it has problems loading the XIB files.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:

I am currently loading the XIB file like this:

NSString* const frameworkBundleID  = @"org.cocoapods.MyPod";
NSBundle *podBundle =[NSBundle bundleWithIdentifier:frameworkBundleID];

earlier I also tried (the below) which worked locally as well.

NSBundle *podBundle = [NSBundle bundleForClass:[self class]];

What could I be doing wrong that makes it work locally but not after publishing?

Just for info, here's how the spec looks:

s.source_files = 'Pod/Classes/**/*.{h,m}'

s.resource_bundles = {
'NetLogger' => ['Pod/Assets/*.xcassets', 'Pod/Classes/*.xib']
}
1

1 Answers

0
votes

I've had the same problem a while ago. I fixed it by using a specific class as a reference instead of self:

NSBundle *podBundle = [NSBundle bundleForClass:[ClassIncludedInPod class]];

For example to load MyViewController I would use:

NSBundle *bundle = [Bundle bundleForClass:[MyViewController class]];
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" 
                                                            bundle:bundle];

Here in Swift:

let bundle = Bundle(for: MyViewController.self)
let myVC = MyViewController(nibName: "MyViewController", bundle: bundle)