I've created a plist (File->New File->Resource plist) file that has a dictionary that stores floating point numbers for a console application. I've pretty much created this plist to store a few numbers to be returned by class methods, but could change so hardcoding isn't really that great of an idea. However, when I try to access the plist file, I always get "nil" for the file path and I'm not sure what I'm doing wrong.
<plist version="1.0">
<dict>
<key>minFloatNumber</key>
<real>520.0</real>
</dict>
</plist>
+ (double) minFloatingPointNunber
{
NSString *path = [[NSBundle mainBundle] pathForResource: @"FloatDictionary"
ofType: @"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile: path];
[path release];
double f = [[dict objectForKey: @"minFloatNumber"] doubleValue];
[dict release];
开发者_高级运维 return f;
}
I've read various articles discussing looking at the project's "Build Phases" and looking at "Copy Bundle Resources," but I don't see any of that anywhere. I'm pretty sure there has to be something wrong with my setup, but not sure what I'm missing, or the steps I need to take to remedy the situation. Thanks in advance for the tips.
The "Console Application" template will be set up to produce a single binary — not included inside a proper bundle, so you can't use the NSBundle
APIs to access files. If you want to include a file, you could make an actual application (where you'll be able to use [NSBundle mainBundle]
), or you could include the data inside the binary (as a compile-time constant or some such).
精彩评论