繁体   English   中英

iOS应用程序中的基本文件结构是什么?

[英]What is the basic file structure in an iOS application?

我正在尝试在我的应用程序中加载一个plist文件

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

但categoryProps数组总是以0个对象结束。 我已将CategoryData.plist文件放在我的项目中的“Supporting Files”目录下,但我无法弄清楚文件在编译的应用程序中的排列方式。

有人可以指向我描述应用程序的文件系统如何布局的文档以及如何确定文件在文件系统中的位置?

我忘了指出我使用的XCode 4没有为项目创建资源文件夹

您的加载代码代码应该用于在文件系统中查找文件。 在一个项目中,我有:

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

我要做的是将plistPath记录到控制台或在调试器中检查它,然后导航到磁盘上的那个位置并确定plist是否在你认为它的位置结束。

此外,在/ Users / <#Username#> / Library / Developer / Xcode / DerivedData / <#Unique Appname#> / Build / Products / Debug-iphonesimulator / <#Appname#>。app中找到您的应用程序包,右键单击然后选择“显示包内容”。 确保您在自己认为应该的位置看到您的plist。

您需要将plist文件放在Resources文件夹中。 然后你就可以像这样加载和使用它们了

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

UPD:在xcode4中,您必须将plist文件放在“Supporting Files”目录而不是“Resources”中。 并尝试使用NSDictionary而不是NSArray

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM