开发者

Load array from plist in Documents Directory

开发者 https://www.devze.com 2022-12-29 08:51 出处:网络
I use to load plist which are in my main Bundle (Ressource folder) into an array using : NSString *path = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:nomPlist ];

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 pli开发者_高级运维st from the Documents directory of my app ? ?

thanks to all


[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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消