开发者

What is the basic file structure in an iOS application?

I'm trying to load a plist file in my application with

NSBundle* bundle = [NSBundle mainBundle];
NSString* plistPath = [bundle pathForResource:@"CategoryData" ofType:@"plist"];
categoryProps = [[NSArray alloc] initWithContentsOfFile:plistPath];

but the categoryProps array always ends up with 0 objects. I've placed the CategoryData.plist file under the "Supporting Files" dir in my project but I can't figure out how files are arranged in the compiled app.

Can someone point me to docs that describe how the file system of an app is laid out and how to figure out where files are located within the file system?

I forgot to point ou开发者_如何学Got that I am using XCode 4 which does not create a resources folder for the project


Your loading code code should work for locating the file within the file system. In a project, I have:

NSString *data = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];

What I would do is log the plistPath to the console or inspect it in the debugger, then navigate to that location on disk and determine if the plist ends up where you think it does.

Also, locate your application bundle in /Users/<# Username #>/Library/Developer/Xcode/DerivedData/<# Unique Appname #>/Build/Products/Debug-iphonesimulator/<# Appname #>.app, right click on it and select "Show package Contents". Ensure that you see your plist where you think you should.


You need to place your plist file in the Resources folder. Then you will be able to load and use them like this

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

UPD: In xcode4 you must to place plist files in the "Supporting Files" directory instead of "Resources". And try to use NSDictionary instead of NSArray

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜