As others have pointed out, bundling a nib file with a static library in the same manner that you might bundle a nib with a framework just isn't possible. A static library contains compiled code only. It is not a container for a collection of code and other resources.
That said, if you're serious about this you have an option that would have the same effect. Basically you'll be base64 encoding your nib into a string, and reconstituting it at runtime. Here's my recipe:
1) compile your .xib to binary .nib form. Use XCode or ibtool.
2) use a tool to encode your .nib as base64 text. On OSX you can use openssl
to do this from the terminal:
openssl base64 -in myNib.nib -out myNib.txt
3) copy/paste the base64 string into one of your source files. Construct a NSString from it:
NSString* base64 = @"\
TklCQXJjaGl2ZQEAAAAJAAAAHgAAADIAAAA2AAAAjAAAAG4AAADuAwAAEQAAAPwG\
AACHgIaChoGPh4eCjoGJj46CnYGCnoGCn4GBoIKEooaKqIGOqYGCqoGQq4iMs4WC\
uIGEuYePwIaBxoWMy4SCz4GG0IGI0YWM1oGE14aL3YeO5IGE5YeC7IGF7YGKVUlG\
...
ZVN0cmluZwCHgQ0AAABVSUZvbnQAiIBOU0FycmF5AIeATlNGb250AI6AVUlQcm94\
eU9iamVjdACIgQMAAABVSUNvbG9yAIeAVUlWaWV3AA==";
4) write code to decode the base64 string into a NSData:
NSData* d = [[NSData alloc] initWithBase64EncodedString: base64 options: NSDataBase64DecodingIgnoreUnknownCharacters];
5) Construct a UINib from the NSData:
UINib* nib = [UINib nibWithData: d bundle: nil];
6) Use your nib:
NSArray* nibItems = [nib instantiateWithOwner: nil options: 0];
Now, you may end up needing to change a few things in your code. If you're creating view controllers from nibs using either init
or initWithNibName:bundle:
, then this isn't going to 'just work'. Why? Because those mechanisms look in a bundle (typically the app bundle) for the nib, and your nib won't be there. But you can fix up any view controllers in your code to load from your UINib that we just reconstituted. Here's a link that describes a process for this: http://www.indelible.org/ink/nib-loading/
You may quickly find that you need other resources available to your code in addition to your .nib. E.g. images. You could use the same approach to embed images or any other resource in your static library.
In my opinion, the developer-cost of the workflow required to keep this embedded nib up to date is pretty high. If it were me I'd just create a framework and distribute that.