美文网首页
读取本地plist数据并修改

读取本地plist数据并修改

作者: yytester | 来源:发表于2017-02-15 15:12 被阅读184次

比如在开发时建了一个plist文件(字典数组):

Paste_Image.png
       let plistPath = Bundle.main.path(forResource: "appData", ofType: "plist")
       //获取属性列表文件中的全部数据
        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!)

相关文章

网友评论

      本文标题:读取本地plist数据并修改

      本文链接:https://www.haomeiwen.com/subject/kyeqwttx.html