Creating a plist file programmatically

nickthedude picture nickthedude · Feb 18, 2010 · Viewed 20.6k times · Source

this question is regarding xcode objective c and iphone development:

So I want to store an array in a new plist file and I know how to retrieve the file path and write the data into the file (at least I think I do) and all that jazz once the plist is created, but how do I actually create the plist file the first time the app is run or the first time I go to enter data into it? I want it to live in the documents folder of my app.

I'm assuming this is pretty simple I just can't seem to find documentation on it.


I ended up using NSKeyedValue there was a great tutorial here:

http://vimeo.com/1454094

I know technically this is not the answer to the question but it did solve my problem.

Answer

Gustaf Carleson picture Gustaf Carleson · Feb 18, 2010

To save:

NSMutableArray *array = [[NSMutableArray alloc] init];
[array writeToFile:[@"/path/to/file.plist"] atomically: TRUE];

To retrieve:

NSMutableArray *array = [[NSMutableArray arrayWithContentsOfFile:[@"/path/to/file.plist"]] retain];