If you want to build your interfaces using interface builder when building a static library you will need to make a bundle and distribute it with your library.
In Xcode:
- File> New> Target
- Select "Bundle" from the OS X Framework and Library section
- Fill in the details. The bundle framework should be core foundation.
Then you need to get your bundle compiled at the same time as your framework. Add the bundle to the "Target Dependencies" build phase of your framework.
When you make your xibs you make their target this new bundle you have created.
Then when you compile your framework in the derived data directory, next to your framework binary you will find your compiled bundle. You give this to your third parties along with the framework binary.
So how do you reference this bundle in your code? In iOS bundles cant be loaded and your bundle will actually be inside the third party's iOS application main bundle. You can create a category on NSBundle for conveniently accessing your bundle from your code:
@interface NSBundle (mybundle)
+(NSBundle *)myBundle;
@end
@implementation NSBundle (mybundle)
static NSBundle * _myBundle;
+(NSBundle *)myBundle{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * pathToMyBundle = [mainBundle pathForResource:@"myBundle" ofType:@"bundle"];
NSAssert(pathToMyBundle, @"bundle not found", nil);
_myBundle = [NSBundle bundleWithPath:pathToMyBundle];
});
return _myBundle;
}
You can then access your bundle in code to load xibs like this:
UIViewController * controller = [[UIViewController alloc] initWithNibName:nil bundle:[NSBundle myBundle]];
Remember that if you use categories in your framework code you will need to make sure that your framework consumers add the -ObjC
(or -all_load
if not using a recent Xcode) "other linker flag" to their projects