Skip to content

Commit

Permalink
更新demo
Browse files Browse the repository at this point in the history
  • Loading branch information
intsig171 committed May 21, 2024
1 parent 4646c31 commit f9d1ca8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Example/SmartCodable/Test3ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,25 @@ class Test3ViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

let json = """
{"code":1,"data":{"index":"4","msg":"上传成功","size":1780},"msg":"success","rid":"Dg0S"}
"""

if let model = mapModel([String: SmartAny].self, jsonString: json) {
print(model)
}
}

func mapModel<T: SmartCodable>(_ type: T.Type, jsonString: String) -> T? {
guard let model = type.deserialize(from:jsonString) else {
return nil
request(model:ResponseData<Dictionary<String,SmartAny>>.self) { response in
print(response)
}
return model
}

struct ResponseData<T: SmartCodable>: SmartCodable{
var code: Int = 0
var msg: String = ""
var data: T?
}

func request<T: SmartCodable>(model: T.Type, completion:((_ response:T?) -> Void)?){
let json = """
{"code":1, "data":{ "index": "4", "msg": " EftI", "size":1780}, "msg": "success", "rid":"DgOS" }
"""
if let model = model.deserialize(from:json) {
completion?(model)
}
}
}

0 comments on commit f9d1ca8

Please sign in to comment.