plist,全名PropertyList,即属性列表文件,文件内容为xml格式,因扩展名为.plist,因此通常被叫做plist文件。
手动创建plist:

选择Property List,设置文件名即可。我创建了一个名为CityList的plist文件,先来看一下新建的plist是什么样的

可以看出plist的每一个row都是Key:Type:Value形式的。Root的type默认为Dictionry,可选为Array,也就暗示了我们在代码中读取一个plist文件得到的必是一个Dictionry or Array。
在Root下新建一条数据

新数据的Type支持的类型有:

我简单的对CityList做了下设置:

有了一个简单的plist文件,我们下面来看看怎么读取它(我将CityList.plist放在了Document目录下),代码如下:

打印为:

现在我要在河北省下面添加一个“沧州”,实现代码如下:

这时CityList.plist的内容变成了这样:

上面是已经存在的plist文件的读取和数据追加,下面是自动创建plist文件并写入数据:


网友评论