在 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)。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)