模擬器,網絡 json 轉 plist 文件,json
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) } }
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) } }