Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a plist file programmatically

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.

like image 424
nickthedude Avatar asked Feb 18 '10 21:02

nickthedude


2 Answers

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];
like image 197
Gustaf Carleson Avatar answered Sep 16 '22 21:09

Gustaf Carleson


 [myArray writeToFile:aFile atomically:YES];
like image 36
Dave DeLong Avatar answered Sep 17 '22 21:09

Dave DeLong