从文档目录中的 plist 加载数组
我使用以下方法将主包(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[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, useNSFileManager
to copy the plist file from your app's bundle to the documents directory. Afterwards, always open it from there.尝试查看应用程序文档目录中的文件是否存在
Try to see if the file in app's documents directory exist