swift *** 作.plist文件 ,解决覆盖的问题

swift  *** 作.plist文件 ,解决覆盖的问题,第1张

概述1.可以覆盖的代码 static func getIP() -> String{ let ipPath = Bundle.main.path(forResource: "ip", ofType: "plist") let ipArr = NSDictionary(contentsOfFile: ipPath!) let ip = ipArr?["ip

1.可以覆盖的代码

static func getIP() -> String{        let ipPath = Bundle.main.path(forResource: "ip",ofType: "pList")        let ipArr = NSDictionary(contentsOffile: ipPath!)        let ip = ipArr?["ip"] as! String        return ip    }    static func setIP(Ip:String){        let ipPath = Bundle.main.path(forResource: "ip",ofType: "pList")        let ipArr = NSDictionary(dictionary: ["ip":Ip])        ipArr.write(tofile: ipPath!,atomically: true)    }

2.不覆盖的代码

func getCacheNativeNSDictionary@H_404_41@(_ sjBasicID:String) -> NSDictionary?{    print("sjBasicID:\(sjBasicID)")    let ipPath = Bundle.main.path(forResource: "nativeCache",ofType: "pList")    let ipArr = NSDictionary(contentsOffile: ipPath!)    let ip = ipArr?[sjBasicID] as? NSDictionary    return ip}func setCacheNativeNSDictionary(_ sjBasicID:String,str:NSDictionary){    let ipPath = Bundle.main.path(forResource: "nativeCache",ofType: "pList")    let ipArr = NSMutableDictionary(contentsOffile: ipPath!)    ipArr?[sjBasicID] = str    ipArr?.write(tofile: ipPath!,atomically: true)}
差别 let ipArr = NSMutableDictionary(contentsOffile: ipPath!) 主要是把.pList文件路径与Dictionary关联,则不会覆盖原来的文件 总结

以上是内存溢出为你收集整理的swift *** 作.plist文件 ,解决覆盖的问题全部内容,希望文章能够帮你解决swift *** 作.plist文件 ,解决覆盖的问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1065081.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存