从文档目录中的 plist 加载数组

发布于 2024-08-31 04:24:19 字数 425 浏览 1 评论 0原文

我使用以下方法将主包(Ressource 文件夹)中的 plist 加载到数组中:

 NSString *path = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:nomPlist ];
 NSMutableArray *tmpQuestion = [[NSArray alloc] initWithContentsOfFile:path];
 arrayQuestion = [ [NSArray alloc] initWithArray:tmpQuestion]; 
 [tmpQuestion release];

因为我决定更改 plist 的内容,并且主包是只读的,我如何使该数组从 Documents 目录加载 plist我的应用程序? ?

感谢大家

I use to load plist which are in my main Bundle (Ressource folder) into an array using :

 NSString *path = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:nomPlist ];
 NSMutableArray *tmpQuestion = [[NSArray alloc] initWithContentsOfFile:path];
 arrayQuestion = [ [NSArray alloc] initWithArray:tmpQuestion]; 
 [tmpQuestion release];

since i decide to change the content of my plist and that main bundle is read only how can i make this array loading plist from the Documents directory of my app ? ?

thanks to all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-09-07 04:24:19

[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]] 将获取应用程序的文档目录。首次启动时,使用 NSFileManager 将 plist 文件从应用程序包复制到文档目录。之后,始终从那里打开它。

[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]] will get you your app's Documents directory. On first launch, use NSFileManager to copy the plist file from your app's bundle to the documents directory. Afterwards, always open it from there.

2024-09-07 04:24:19

尝试查看应用程序文档目录中的文件是否存在

  • 是:然后使用此文件
  • 否:这是第一次启动,因此从应用程序包中复制它

Try to see if the file in app's documents directory exist

  • YES : then use this file
  • NO : this is the first launch, so copy it from the apps's bundle
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文