模拟器,网络 json 转 plist 文件,
Net.request(.get(key)) { (result) in
do{
let data = try result.get().data
do{
let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions())
if let dict = json as? [String: Any], let src = dict["data"] as? NSDictionary{
// 写入数据
src.write(toFile: "/Users/Pictures/one.plist", atomically: true)
}
}
catch let error{
print(error)
}
}
catch{
print(error)
}
}
便捷的写法,当然是 NSDictionary 写入路径字符串
配套的解析代码:
if let src = Bundle.main.url(forResource: "one", withExtension: "plist"){
do {
let data = try Data(contentsOf: src)
let decoder = PropertyListDecoder()
let resp = try decoder.decode(HanCatalog.self, from: data)
// ...
} catch {
print(error)
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。