0

我是 Objective-c 的新手,想了解如何设置应用程序主目录的文件路径。对于测试和开发,我一直在我的硬盘驱动器上手动放入属性列表的路径,但现在我想捆绑它 - 或者只是存档并分发它以作为没有 Xcode 测试构建的应用程序进行测试......我已经一直在用这个...

NSString* pListPath = @"/Users/-----/Saves/Resourcing/resourcingProperties.plist";
NSMutableDictionary *pListDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:pListPath];
NSMutableDictionary* interfaceKeysDictionary = [pListDictionary valueForKey:@"Interface Keys"];
NSMutableDictionary* valueSavesDictionary = [pListDictionary valueForKey:@"Value Saves"];

将应用程序捆绑为我的应用程序文件夹中的独立应用程序后,如何使用应用程序主目录的路径?

4

1 回答 1

1

对于您要执行的操作,您不希望或不需要直接读取 plist 文件。你只需调用:

NSBundle* mainBundle = [NSBundle mainBundle]; // or [NSBundle bundleWithIdentifier]
NSDictionary* infoDict = [mainBundle infoDictionary];
NSMutableDictionary* plistDictionary = [NSMutableDictionary dictionaryWithDictionary:infoDict];

然后,您可以根据需要在代码中添加它。

于 2012-10-06T18:26:54.533 回答