views:

547

answers:

1

I've created a static library in Xcode, which I am able to successfully use in other projects. However, with resources like plists, I find I must include any plists referenced in my library in the main project where the project is used.

In my static library project, I have my plist included in the "Copy Bundle Resources" phase of the target. In my code, here is what I am doing:

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath   = [mainBundle pathForResource:@"MyClassParams" ofType:@"plist"];

NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

If I use mainBundle and the MyClassParams.plist is included in the main project, all is good. If MyClassParams.plist is included in the library project, it doesn't work.

On the assumption that [NSBundle mainBundle] was referencing the wrong static method to use, I replaced it with:

NSBundle *mainBundle = [NSBundle bundleForClass:[MyClass class]];

This did not work either.

So, is it possible to include a plist or any other resources with a static library -- or do I have to include whatever I need in the project where the lib is used?

+3  A: 

Static Libraries are not in bundles, when they get linked into an application they are part of that applications bundle. On the iPhone, effectively all code you write will be in the mainBundle since you can't include embedded frameworks.

So yes, you need to copy over all the resources into the project you are linking the static framework into.

Louis Gerbarg
Thank you for the answer.
Vjayus