Swift删除项目plist

时间:2014-11-16 13:50:08

标签: swift ios8

在我的progect中,我在这个模式下在plist上添加一个项目

//Get path of Documents directory
var paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
var documentsDirectory:AnyObject = paths[0]
var path = documentsDirectory.stringByAppendingPathComponent("samplePlist.plist")
var fileManager = NSFileManager.defaultManager()
var fileExists:Bool = fileManager.fileExistsAtPath(path)
var data : NSMutableDictionary?
//Check if plist file exists at path specified
if fileExists == false {
//File does not exists
data = NSMutableDictionary () //Create data dictionary for storing in plist
} else  {
//File exists – retrieve data from plist inside data dictionary
data = NSMutableDictionary(contentsOfFile: path)
}
data?.setValue("hi", forKey: "NameButton")

我的plist就是这个

<dict>
<key>NameButton</key>
<string>1</string>
</dict>
</plist>

如果我想从我的plist中删除NameButton?

0 个答案:

没有答案