In my Iphone app, I previously loaded a standard plist file into a Dictionary, by doing the following code. Recently I copied the source, and the plist file to a new bundle, which I compile into a framework and use in the original app. All the code is running, but the plist loading code can't find the settings.plist file anymore. Looking at the path, it still seems to be looking in the main app's files.
Do I need to update this bundle somehow to read the frameworks embedded resources?
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [[bundle resourcePath] stringByAppendingPathComponent:@"settings.plist"];
_plistDictionary = [[NSDictionary alloc] initWithContentsOfFile:path];
If I'm understanding you correctly, yes.
+[NSBundle mainBundle] returns the NSBundle object that corresponds to the directory where the current application executable is located. So in short, it's going to return the main application's bundle, which is not what you want (you want the bundle of a framework, within your application's bundle).
Since you want to obtain the bundle for your framework, if the code to load that plist resides in the framework itself, you could do something like this:
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
which would then return the bundle for the framework. Or more specifically, the bundle in which that class (this code) resides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With