I built a framework and a cocoa application in Mac OS X. The framework is dynamically linked to the application. In a class of the framework, I need to read a resource file within this framework's resources folder. The code below
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *characterCodeTable = [resourcePath stringByAppendingPathComponent:@"pymb.txt"];
does not work since "resourcePath" is the path to application's resources folder, not the framework's.
So how can I access the framework's resource folder in the code in this framework itself?
BTW: Is there any best practice to organize miscellaneous files in a framework/application bundle?
Instead of calling +[NSBundle mainBundle]
, call either +[NSBundle bundleWithIdentifier:]
or +[NSBundle bundleForClass:]
. The former takes an NSString
argument of the framework's indentifier; the latter takes a Class
argument of a class provided by the framework. Then, you can call the usual NSBundle
paths as necessary.
Full documentation can be found here.
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