开发者

Update plist file in File Sharing folder - I really need advice

I need to open a plist file located in the File Sharing folder, to add two pieces of user info to each time the app is launched; as in a new Name and Email of the user (both are of type NSString and the plist file is D开发者_如何学Pythonictionary).

It then needs to save the file back to the File Sharing folder again, so that the new updated plist file can be removed at a later time via iTunes.

If anyone could help it would be greatly appreciated


Storing a plist in the Documents directory is possible. You will be able to load the plist into an NSMutableDictionary, modify the dictionary and write it back out to the Documents directory.

// get the path to the plist file
NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
NSString *documentsPath = [paths objectAtIndex:0]; 
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myfile.plist"];

// read the plist into an NSMutableDictionary
NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];

// make the additions to the plistDictionary

// write the plist back to the documents directory
[plistDictionary writeToFile:filePath atomically:YES];

I don't know that you will be able to remove the plist via iTunes.


Another great resource that I found was an article by the "Humble Coder's" blog at the following location. Great advice and the example code was spot on for my need to save retrieve and update my plist files. Thank you again to those that helped.

http://humblecoder.blogspot.com/2010/03/revisited-storing-and-retrieving.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜