nbo*_*jja 5 iphone cocoa-touch plist
我正在开发一个iPhone应用程序,我想在其中使用.plist文件来保存一些配置变量.
在我的xcode中,在哪里创建.plist文件以及如何访问它?
谢谢,
你会放入资源文件夹.然后使用这样的东西加载它:
NSString *file = [[NSBundle mainBundle] pathForResource:@"TwitterUsers" ofType:@"plist"];
NSArray *Props = [[NSArray alloc] initWithContentsOfFile:file];
Run Code Online (Sandbox Code Playgroud)
TwitterUsers是plist文件的名称.
如果你的plist文件包含键和值,你可以使第二行成为NSDictionary而不是NSArray.
要将plist文件存储在Documents目录中,您必须在应用程序中包含plist文件,然后在首次启动时将其复制到Documents目录.
要访问Documents目录中的文件:
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
// <Application Home>/Documents/foo.plist
NSString *fooPath =
[documentsPath stringByAppendingPathComponent:@“foo.plist”];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10193 次 |
| 最近记录: |