比如在開發(fā)時(shí)建了一個plist文件(字典數(shù)組):
Paste_Image.png
let plistPath = Bundle.main.path(forResource: "appData", ofType: "plist")
//獲取屬性列表文件中的全部數(shù)據(jù)
let array = NSMutableArray(contentsOfFile: plistPath!)
for item in array! {
let dict = item as! NSDictionary
var name2 = "修改后的name"
var url2 = "修改后的url"
dict.setValue(name2, forKey: "app_name")
dict.setValue(url2, forKey: "app_url")
array?.write(toFile: plistPath!, atomically: true)
}
//輸出修改后的plist文件
let x2 = NSMutableArray(contentsOfFile: plistPath!)