mag_zbc
mag_zbc

Reputation: 6992

Cannot access resources bundle

I have a project with several targets:

Now, what I'm trying to do is to access resources from Resources inside MyLib. I've added Resources in Target Dependencies and in Copy Bundle Resources in both MyLib and App. In Resources, I've added all the files I will need to Copy Bundle Resources.

However, I cannot access the Resources bundle, neither in My Lib, nor in App. [NSBundle bundleWithIdentifier] returns nil. In MyLib, when I list all bundles with [NSBundle allFrameworks] or [NSBundle allBundles], I can see the App bundle, but not Resouces bundle. Any help?

Upvotes: 1

Views: 836

Answers (1)

mag_zbc
mag_zbc

Reputation: 6992

I managed to find the answer:

Apparently, bundleWithIdentifier does not load a bundle. Documentation seems to be a little vague on this:

This method creates and returns a new NSBundle object if there is no existing bundle associated with identifier. Otherwise, the existing instance is returned.

One might expect that you can just load a bundle with it, which is not the case. You need to load the bundle explicitly with bundleWithPath, like so:

NSBundle *bundle = [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"Resources.bundle"]];

That fixed it for me.

Upvotes: 1

Related Questions