如何在Swift中将plist作为字典?

如何在Swift中将plist作为字典?,第1张

如何在Swift中将plist作为字典

Swift 3.0中, 从Plist读取。

func readPropertyList() {        var propertyListFormat =  PropertyListSerialization.PropertyListFormat.xml //Format of the Property List.        var plistdata: [String: AnyObject] = [:] //Our data        let plistPath: String? = Bundle.main.path(forResource: "data", ofType: "plist")! //the path of the data        let plistXML = FileManager.default.contents(atPath: plistPath!)!        do {//convert the data to a dictionary and handle errors. plistData = try PropertyListSerialization.propertyList(from: plistXML, options: .mutableContainersAndLeaves, format: &propertyListFormat) as! [String:AnyObject]        } catch { print("Error reading plist: (error), format: (propertyListFormat)")        }    }

阅读更多 如何在SWIFT中使用属性列表(.PLIST)。



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

原文地址: https://outofmemory.cn/zaji/5020036.html

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

发表评论

登录后才能评论

评论列表(0条)

保存