Creating a plist file programmatically

北慕城南 提交于 2019-12-18 11:17:36

问题


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.


回答1:


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];



回答2:


 [myArray writeToFile:aFile atomically:YES];


来源:https://stackoverflow.com/questions/2292347/creating-a-plist-file-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!