I have a static library that gets linked to by an application. The library code opens a file that is in bundle that is in the application bundle, the opening is done as:
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"];
This is working fine.
However I want to add some unit test code to the library, and so I have a logic test target for it. As the file is in the bundle for the application and not in the bundle for the static library I copied the Config.plist
file and added it to the test code target via Copy Bundle Resources
. However when I execute the test code the file cannot be found. Why is that?
In that the above is confusing, here's a summary of the workspace structure.
Workspace contains:
Application Project with application target, which contains (X)
Config.plist (a)
Library project which contains:
Library target, which contains:
the code opening the file in the bundle (b)
Test library target, which contains: (Y)
A Copy of the Config.plist (c)
So if I build X then when b runs it can find a. But when I build Y when it runs then b can't find c.
I found if I changed [Bundle mainBundle] to [NSBundle bundleForClass:[self class]] then it works in both cases
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