Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8: How to load xib from Dynamic Framework

I am using Cocoapods pre-release 0.36 to build and deploy a private dynamic framework into an app bundle. I am using the resources attribute to copy xibs, and they show up in the app bundle.

s.subspec 'Views' do |ss|
    ...
    ss.resources = ['All/My/Folders/**/*.{xib,png}']
    ...

I am trying to load reusable controls from the xibs like this:

NSBundle.mainBundle().loadNibNamed("MyXib", owner:loader, options:nil)

but this is failing as it cannot find the xib in my embedded sub framework. The actual xib (nib) paths follow the pattern:'

./Frameworks/MyPrivateFramework.framework/MyXib.nib

My question is, is there a simple, code agnostic way of loading the xib that will work when packaged in an iOS 8 framework - or do I have to explicitly hardcode in the above path? The above loading code worked until I think the dynamic framework change.

Thanks

like image 595
Chris Conover Avatar asked Dec 03 '22 18:12

Chris Conover


1 Answers

From this post here:

http://artsy.github.io/blog/2015/01/04/cocoapods-and-frameworks/

I arrived at the agnostic solution of getting the framework bundle from a class within, ie:

NSBundle(forClass: ClassInFramework.self)

and then loading the xib from that:

NSBundle(forClass: ClassInFramework.self)
    .loadNibNamed("ClassInFramework", owner:loader, options:nil)

and that worked.

like image 78
Chris Conover Avatar answered Dec 23 '22 17:12

Chris Conover