以编程方式创建plist文件 [英] Creating a plist file programmatically

查看:82
本文介绍了以编程方式创建plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于xcode目标c和iphone开发的:

this question is regarding xcode objective c and iphone development:

所以我想将数组存储在新的plist文件中,并且我知道如何检索文件路径并将数据写入文件(至少我认为是这样)以及创建plist后的所有爵士乐,但是我如何在首次运行该应用程序或第一次进入该应用程序中创建数据时自动创建plist文件?我希望它位于我应用程序的documents文件夹中.

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.

我最终使用了NSKeyedValue,这里有个很棒的教程:

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.

推荐答案

要保存:

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

要检索:

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

这篇关于以编程方式创建plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆