88
99import SmartCodable
1010import BTPrint
11- import CodableWrapper
1211
1312class Test2ViewController : BaseViewController {
1413
1514 override func viewDidLoad( ) {
1615 super. viewDidLoad ( )
1716
1817
19- let dict : [ String : Any ] = [
20- " name " : " Mccc " ,
21- " age " : 20 ,
22- ]
23-
24- let model = StudentModel . deserialize ( from: dict)
25- print ( model? . name as Any )
26- print ( model? . age as Any )
27-
28- let transDict = model? . toJSONString ( prettyPrint: true ) ?? " "
29- print ( " \n Model -> JSON " )
30- print ( transDict)
18+ // let dict: [String: Any] = [
19+ // "name": "Mccc",
20+ // "age": 20,
21+ // ]
22+ //
23+ // let model = StudentModel.deserialize(from: dict)
24+ // print(model?.name as Any)
25+ // print(model?.age as Any)
26+ //
27+ // let transDict = model?.toJSONString(prettyPrint: true) ?? ""
28+ // print("\n Model -> JSON")
29+ // print(transDict)
3130 }
3231
3332 class BaseModel : SmartCodable {
@@ -39,8 +38,51 @@ class Test2ViewController: BaseViewController {
3938 class StudentModel : BaseModel {
4039 var age : Int ?
4140 }
41+
42+ override func touchesBegan( _ touches: Set < UITouch > , with event: UIEvent ? ) {
43+ testSmartCodableInherit ( )
44+ }
4245}
4346
4447
4548
4649
50+ enum Gender : Int , SmartCaseDefaultable {
51+ case unknown
52+ case male
53+ case female
54+ }
55+
56+ class SMCClassAnimal : SmartCodable {
57+ var age : Int = 0
58+ var sex : Gender = . unknown
59+
60+ required init ( ) { }
61+ }
62+
63+ @SmartSubclass
64+ class SMCClassPerson : SMCClassAnimal {
65+ var name : String ?
66+ var motto : String ?
67+ var height = 0
68+ var temp = 0
69+ var a = 1.1
70+ var b = false
71+ var c = " "
72+ var d = Date ( )
73+ var e = Date ( )
74+ }
75+
76+ func testSmartCodableInherit( ) {
77+ let deJsonStr = """
78+ {
79+ " name " : " 张三丰 " ,
80+ " age " : " 23 " ,
81+ " motto " : " nothing is possible. " ,
82+ " sex " : 1,
83+ " height " : 175
84+ }
85+ """
86+ let obj = SMCClassPerson . deserialize ( from: deJsonStr)
87+ print ( " height: " , obj? . height)
88+ }
0 commit comments