views:

32

answers:

2

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 Dictionary).

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

A: 

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.

TomH
That is awesome TomH. It worked great. I enabled file sharing in my -info.plist file and was able to access it via iTunes. thx again.
GMoP
If you like the answer, please accept it.
TomH
A: 

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

GMoP