diff --git a/Document/TestCaseSpecification.xmind b/Document/TestCaseSpecification.xmind index 30af7e7..a2f7626 100644 Binary files a/Document/TestCaseSpecification.xmind and b/Document/TestCaseSpecification.xmind differ diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 4683327..970fe59 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -8,7 +8,7 @@ PODS: - FBSnapshotTestCase/SwiftSupport (2.1.4): - FBSnapshotTestCase/Core - HandyJSON (5.0.0-beta.1) - - SmartCodable (4.0.4) + - SmartCodable (4.1.0) - SnapKit (5.6.0) DEPENDENCIES: @@ -39,7 +39,7 @@ SPEC CHECKSUMS: CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980 FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978 - SmartCodable: 91f469249cf9cd8c1ef4777bffe902e167293846 + SmartCodable: 04f61a30bd6567fc15b71e718e1aee4766956e55 SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25 PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f diff --git a/Example/Pods/Local Podspecs/SmartCodable.podspec.json b/Example/Pods/Local Podspecs/SmartCodable.podspec.json index f839830..b7a75a4 100644 --- a/Example/Pods/Local Podspecs/SmartCodable.podspec.json +++ b/Example/Pods/Local Podspecs/SmartCodable.podspec.json @@ -1,6 +1,6 @@ { "name": "SmartCodable", - "version": "4.0.4", + "version": "4.1.0", "summary": "数据解析库", "homepage": "https://github.com/intsig171", "license": { @@ -12,7 +12,7 @@ }, "source": { "git": "https://github.com/intsig171/SmartCodable.git", - "tag": "4.0.4" + "tag": "4.1.0" }, "platforms": { "ios": "11.0", diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 4683327..970fe59 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -8,7 +8,7 @@ PODS: - FBSnapshotTestCase/SwiftSupport (2.1.4): - FBSnapshotTestCase/Core - HandyJSON (5.0.0-beta.1) - - SmartCodable (4.0.4) + - SmartCodable (4.1.0) - SnapKit (5.6.0) DEPENDENCIES: @@ -39,7 +39,7 @@ SPEC CHECKSUMS: CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980 FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978 - SmartCodable: 91f469249cf9cd8c1ef4777bffe902e167293846 + SmartCodable: 04f61a30bd6567fc15b71e718e1aee4766956e55 SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25 PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f diff --git a/Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist b/Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist index b88155c..c8bd5a0 100644 --- a/Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist +++ b/Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.0.4 + 4.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/SmartCodable.xcodeproj/project.pbxproj b/Example/SmartCodable.xcodeproj/project.pbxproj index 8c50745..8bccbac 100644 --- a/Example/SmartCodable.xcodeproj/project.pbxproj +++ b/Example/SmartCodable.xcodeproj/project.pbxproj @@ -37,10 +37,12 @@ 99328D9A2B513A300074036A /* area.json in Resources */ = {isa = PBXBuildFile; fileRef = 99328D982B5138210074036A /* area.json */; }; 993822D42B5E52C0007D3268 /* BaseTwoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 993822D32B5E52C0007D3268 /* BaseTwoViewController.swift */; }; 9955576E2BE0DCC6005F9ABD /* Introduce_10ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9955576D2BE0DCC6005F9ABD /* Introduce_10ViewController.swift */; }; + 9955AC502C32B08700D25466 /* Container_keyedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9955AC4F2C32B08700D25466 /* Container_keyedViewController.swift */; }; + 9955AC522C32B0FD00D25466 /* Container_unKeyedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9955AC512C32B0FD00D25466 /* Container_unKeyedViewController.swift */; }; 9956B9B92BD92D1900C711F5 /* DecodingArrayLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9956B9B82BD92D1900C711F5 /* DecodingArrayLogViewController.swift */; }; 9957743B2BFD95E4003613C5 /* SpecialData_ColorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9957743A2BFD95E4003613C5 /* SpecialData_ColorViewController.swift */; }; 995E03BD2C12F727009E1E5B /* Encode_IgnoredKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995E03BC2C12F727009E1E5B /* Encode_IgnoredKeyViewController.swift */; }; - 995E03C02C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995E03BF2C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift */; }; + 995E03C02C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995E03BF2C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift */; }; 995E03C22C182C68009E1E5B /* Introduce_11ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995E03C12C182C68009E1E5B /* Introduce_11ViewController.swift */; }; 99675FD02B3EC750006C83EC /* airports10000.json in Resources */ = {isa = PBXBuildFile; fileRef = 99AE7D8C2B3EC02E00B474E5 /* airports10000.json */; }; 99675FD12B3EC822006C83EC /* airports1000.json in Resources */ = {isa = PBXBuildFile; fileRef = 99AE7D8F2B3EC02E00B474E5 /* airports1000.json */; }; @@ -178,10 +180,12 @@ 99328D982B5138210074036A /* area.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = area.json; sourceTree = ""; }; 993822D32B5E52C0007D3268 /* BaseTwoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTwoViewController.swift; sourceTree = ""; }; 9955576D2BE0DCC6005F9ABD /* Introduce_10ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Introduce_10ViewController.swift; sourceTree = ""; }; + 9955AC4F2C32B08700D25466 /* Container_keyedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container_keyedViewController.swift; sourceTree = ""; }; + 9955AC512C32B0FD00D25466 /* Container_unKeyedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container_unKeyedViewController.swift; sourceTree = ""; }; 9956B9B82BD92D1900C711F5 /* DecodingArrayLogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingArrayLogViewController.swift; sourceTree = ""; }; 9957743A2BFD95E4003613C5 /* SpecialData_ColorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpecialData_ColorViewController.swift; sourceTree = ""; }; 995E03BC2C12F727009E1E5B /* Encode_IgnoredKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_IgnoredKeyViewController.swift; sourceTree = ""; }; - 995E03BF2C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_ContainerViewcontroller.swift; sourceTree = ""; }; + 995E03BF2C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_ContainerDictViewcontroller.swift; sourceTree = ""; }; 995E03C12C182C68009E1E5B /* Introduce_11ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Introduce_11ViewController.swift; sourceTree = ""; }; 99675FD62B3EC930006C83EC /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 99675FD82B3EC930006C83EC /* NSDictionary+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSDictionary+Extension.swift"; sourceTree = ""; }; @@ -439,7 +443,7 @@ 995E03BE2C12F926009E1E5B /* Container */ = { isa = PBXGroup; children = ( - 995E03BF2C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift */, + 995E03BF2C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift */, ); path = Container; sourceTree = ""; @@ -600,6 +604,8 @@ 99A494E52B9028EB00393193 /* 数据测试 */ = { isa = PBXGroup; children = ( + 9955AC4F2C32B08700D25466 /* Container_keyedViewController.swift */, + 9955AC512C32B0FD00D25466 /* Container_unKeyedViewController.swift */, 99CABA2A2B916DD30070DED0 /* BaseData */, 99CABA2B2B916DE40070DED0 /* Container */, 99D945882B91C4D500CC6470 /* SpecialData */, @@ -986,6 +992,7 @@ 99D945842B9182C800CC6470 /* Container_ArrayNestDictViewController.swift in Sources */, 9905129F2C08299200A2C5D8 /* Decoding_keyIgnoreViewController.swift in Sources */, 99D945852B9182C800CC6470 /* Container_DictNestDictViewController.swift in Sources */, + 9955AC502C32B08700D25466 /* Container_keyedViewController.swift in Sources */, 996760212B3EC930006C83EC /* ArraySafe.swift in Sources */, 99CE4D5D2BC699D10006D435 /* BeforeDecodingViewController.swift in Sources */, 996760292B3EC930006C83EC /* BaseData_StringViewController.swift in Sources */, @@ -999,6 +1006,7 @@ 9967602B2B3EC930006C83EC /* Introduce_8ViewController.swift in Sources */, 99CE4D662BC6AFC90006D435 /* IntroduceViewController.swift in Sources */, 99153D772BD1124C004C01AD /* Test3ViewController.swift in Sources */, + 9955AC522C32B0FD00D25466 /* Container_unKeyedViewController.swift in Sources */, 991452AA2BB50B2A00970575 /* KeyDecodingStrategyViewController.swift in Sources */, 99CE4D522BC687700006D435 /* Test2ViewController.swift in Sources */, 99C313342B99C32A0065FC45 /* Introduce_7ViewController.swift in Sources */, @@ -1010,7 +1018,7 @@ 996760392B3EC930006C83EC /* CaseFourViewController.swift in Sources */, 998567222C11C6620021B7FD /* Encode_SpecialData_colorViewController.swift in Sources */, 99C3138E2B9B38910065FC45 /* CaseSevenViewController.swift in Sources */, - 995E03C02C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift in Sources */, + 995E03C02C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift in Sources */, 998567132C11C0C60021B7FD /* Encode_BaseData_StringViewController.swift in Sources */, 993822D42B5E52C0007D3268 /* BaseTwoViewController.swift in Sources */, 99D9458A2B91C75600CC6470 /* SpecialData_dateViewController.swift in Sources */, diff --git a/Example/SmartCodable/Test2ViewController.swift b/Example/SmartCodable/Test2ViewController.swift index ffc3e92..ba967bb 100644 --- a/Example/SmartCodable/Test2ViewController.swift +++ b/Example/SmartCodable/Test2ViewController.swift @@ -11,40 +11,83 @@ import SmartCodable import HandyJSON + + + class Test2ViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - let jsonString = """ - { - "array": [ - null, - { - "element": 3 - } - ] + SmartConfig.debugMode = .verbose + + let dict1: [String: Any] = [ + : + ] + + let dict2: [String: Any] = [ + "arr": NSNull(), + "optionalArr": NSNull(), + "arr1": NSNull(), + "optionalArr1": NSNull() + ] + + let dict3: [String: Any] = [ + "arr": 1, + "optionalArr": 2, + "arr1": 3, + "optionalArr1": 4 + ] + + let dict4: [String: Any] = [ + "arr": [[ "name": "mccc1" ], [ "name": "mccc2" ]], + "optionalArr": [[ "name": "mccc1" ], [ "name": "mccc2" ]], + ] + + + + print("-------------- 无key") + if let model = FeedModel.deserialize(from: dict1) { + smartPrint(value: model) + } + + print("-------------- null") + if let model = FeedModel.deserialize(from: dict2) { + smartPrint(value: model) } - """ - let jsonString1 = """ - { - "array": [ - null, - ] + print("-------------- 类型错误") + if let model = FeedModel.deserialize(from: dict3) { + smartPrint(value: model) } - """ - if let model = OptionalArrayElementsExample.deserialize(from: jsonString) { + print("-------------- 解析正确的") + if let model = FeedModel.deserialize(from: dict4) { smartPrint(value: model) } + } - struct OptionalArrayElementsExample: SmartCodable { - @SmartFlat - var array: [ArrayElement] = [] + //模型 + struct FeedModel: SmartCodable { +// var arr: [Int] = [] +// var optionalArr: [Int]? +// var optionalArr: [Int]? = [1, 1, 1] + +// var arr: [Int?] = [] +// var optionalArr: [Int?]? +// var optionalArr: [Int?]? = [1, 1, 1] + +// @SmartAny +// var arr: [Any] = [] +// @SmartAny +// var optionalArr: [Any]? + + + var arr: [SubModel] = [] + var optionalArr: [SubModel]? } - - struct ArrayElement: SmartCodable { - var element: Int = 0 + + struct SubModel: SmartCodable { + var name: String? } } diff --git a/Example/SmartCodable/Test3ViewController.swift b/Example/SmartCodable/Test3ViewController.swift index 0d3febc..248b5ad 100644 --- a/Example/SmartCodable/Test3ViewController.swift +++ b/Example/SmartCodable/Test3ViewController.swift @@ -19,29 +19,30 @@ class Test3ViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - let jsonString = """ - { - "46": "aa", - "47": 100, - } - """ - if let model = SubModel.deserialize(from: jsonString) { + let dict: [String: Any] = [ + "subModel": [ + "name": NSNull() + ], + "dict": ["a":1, "b": NSNull(), "c": ["aa": 2]], + "arr": [1, "2", "Mccc", [1,2,3]] + ] + if let model = Model.deserialize(from: dict) { smartPrint(value: model) } } - - struct SubModel: SmartCodable { - var a46: String? - var b47: Int? + + struct Model: SmartCodable { + @SmartAny + var dict: Any? + @SmartAny + var arr: Any? - static func mappingForKey() -> [SmartKeyTransformer]? { - [ - CodingKeys.a46 <--- ["1314520", "5201314"], - CodingKeys.b47 <--- "47", - ] - } - +// var subModel: SubModel? + } + + struct SubModel: SmartCodable { + var name: String? } } diff --git a/Example/SmartCodable/TestViewController.swift b/Example/SmartCodable/TestViewController.swift index c67d7f1..414fe6a 100644 --- a/Example/SmartCodable/TestViewController.swift +++ b/Example/SmartCodable/TestViewController.swift @@ -13,26 +13,54 @@ import HandyJSON import CleanJSON import BTPrint + + +/** 字典的值情况 + * 无key + * 值为null + * 值类型错误 + */ + +/** 字典的类型情况 + * 非可选基础字典 + * 可选基础字典 + * + * 非可续Model + * 可选Model + * + * 使用 SmartAny 修饰 + * 使用 SmartPlat 修饰 + * + */ + + + + + class TestViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - let jsonStr = """ - { - "age": "18", - "weight": "65.4", - "sex": "1" - } - """ - if let model = ZJSmartCodableModel.deserialize(from: jsonStr) { + SmartConfig.debugMode = .none + + + + let arr = [ + ["name": "mccc1", "age": 20, "hobby": [1, 2, 3, "4"]], + ["name": "mccc2", "age": 30], + ] + + + if let model = [FeedModel].deserialize(from: arr) { smartPrint(value: model) } + } //模型 - struct ZJSmartCodableModel: SmartCodable { + struct FeedModel: SmartCodable { + var name: String = "" var age: Int? - var weight: Double? - var sex: Bool? + var hobby: [String] = [] } } diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerDictViewcontroller.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerDictViewcontroller.swift" new file mode 100644 index 0000000..40f2744 --- /dev/null +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerDictViewcontroller.swift" @@ -0,0 +1,33 @@ +// +// Encode_ContainerDictViewcontroller.swift +// SmartCodable_Example +// +// Created by qixin on 2024/6/7. +// Copyright © 2024 CocoaPods. All rights reserved. +// + +import SmartCodable + + +class Encode_ContainerDictViewcontroller: BaseViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + let jsonStr = """ + { + "age": "18", + "weight": "65.4", + "sex": "1" + } + """ + if let model = FeedModel.deserialize(from: jsonStr) { + smartPrint(value: model) + } + } + //模型 + struct FeedModel: SmartCodable { + var dict: [String: String] = [:] + var optionalDict: [String: String]? + } +} diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerViewcontroller.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerViewcontroller.swift" deleted file mode 100644 index 0add406..0000000 --- "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\347\274\226\347\240\201/Container/Encode_ContainerViewcontroller.swift" +++ /dev/null @@ -1,9 +0,0 @@ -// -// Encode_ContainerViewcontroller.swift -// SmartCodable_Example -// -// Created by qixin on 2024/6/7. -// Copyright © 2024 CocoaPods. All rights reserved. -// - -import Foundation diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/TestCaseViewController.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/TestCaseViewController.swift" index eb11512..89d3999 100644 --- "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/TestCaseViewController.swift" +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/TestCaseViewController.swift" @@ -20,6 +20,7 @@ class TestCaseViewController: BaseViewController { dataArray = [ + testCaseZero, testCaseOne, testCaseThree, testCaseTwo, @@ -43,6 +44,18 @@ class TestCaseViewController: BaseViewController { extension TestCaseViewController { + + var testCaseZero: [String: Any] { + [ + "title": "CaseOne - Container测试", + "list": [ + ["name": "类型兼容 - keyed", "vc": "Container_keyedViewController"], + ["name": "类型兼容 - unKeyed", "vc": "Container_unKeyedViewController"], + ] + ] + } + + var testCaseOne: [String: Any] { [ "title": "CaseOne - 基础数据测试", @@ -52,13 +65,6 @@ extension TestCaseViewController { ["name": "类型兼容 - Int8", "vc": "BaseData_Int8ViewController"], ["name": "类型兼容 - String", "vc": "BaseData_StringViewController"], ["name": "类型兼容 - Float", "vc": "BaseData_FloatViewController"], - - - - - - - ] ] } diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictKeylessViewController.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictKeylessViewController.swift" index bfe6737..b024812 100644 --- "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictKeylessViewController.swift" +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictKeylessViewController.swift" @@ -22,7 +22,7 @@ class Container_DictKeylessViewController: BaseCompatibilityViewController { print("\n\n") - optionalType(json: json) +// optionalType(json: json) } } diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictViewController.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictViewController.swift" index f0f6b17..6b27577 100644 --- "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictViewController.swift" +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container/Dict/Container_DictViewController.swift" @@ -19,64 +19,177 @@ class Container_DictViewController: BaseViewController { super.viewDidLoad() - let dict: [String: Any] = [ - - "dict2": NSNull(), - "dict3": [ - "key1": 123, - "key2": "123", - "key3": [1, 2, 3] - ], - - "dict5": NSNull(), - "dict6": [ - "name": "Mccc" - ], - - - "sub2": NSNull(), - "sub3": [ - "name": "Mccc" - ], - - "sub5": NSNull(), - "sub6": [ - "name": "Mccc" - ] - ] +// let dict1 = getDict1() +// guard let feed = Model1.deserialize(from: dict1) else { return } +// smartPrint(value: feed) - guard let feed = Model.deserialize(from: dict) else { return } - smartPrint(value: feed) + +// let dict2 = getDict2() +// guard let feed2 = Model2.deserialize(from: dict2) else { return } +// smartPrint(value: feed2) + + +// let dict3 = getDict3() +// guard let feed3 = Model3.deserialize(from: dict3) else { return } +// smartPrint(value: feed3) + + + let dict4 = getDict4() + guard let feed4 = Model4.deserialize(from: dict4) else { return } + smartPrint(value: feed4) } } + + + + +/// 验证是keyedcontainer容器是字典的情况 extension Container_DictViewController { - struct Model: SmartCodable { + + func getDict1() -> [String: Any] { + return [ + "dict2": NSNull(), + "dict3": 123, + "dict4": ["a": 1, "b": "2", "c": "3"], + + "dict6": NSNull(), + "dict7": 123, + "dict8": ["a": 1, "b": "2", "c": "3"] + ] + } + + + struct Model1: SmartCodable { + // 无key var dict1: [String: String] = [:] + // 值为null var dict2: [String: String] = [:] - @SmartAny - var dict3: [String: Any] = [:] - + // 值类型错误 + var dict3: [String: String] = [:] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var dict4: [String: String] = [:] + - var dict4: [String: String]? var dict5: [String: String]? var dict6: [String: String]? + var dict7: [String: String]? + var dict8: [String: String]? + } +} + + +/// 验证是keyedcontainer容器是Model的情况 +extension Container_DictViewController { + + func getDict2() -> [String: Any] { + return [ + "model2": NSNull(), + "model3": 123, + "model4": ["name": "mccc", "age": "20"], + + "model6": NSNull(), + "model7": 123, + "model8": ["name": "mccc", "age": "20"], + ] + } + + + struct Model2: SmartCodable { - var sub1 = SubModel() - var sub2 = SubModel() - var sub3 = SubModel() + // 无key + var model1 = SubModel() + // 值为null + var model2 = SubModel() + // 值类型错误 + var model3 = SubModel() + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var model4 = SubModel() + - var sub4: SubModel? - var sub5: SubModel? - var sub6: SubModel? -// + var model5: SubModel? + var model6: SubModel? + var model7: SubModel? + var model8: SubModel? } struct SubModel: SmartCodable { var name: String = "" + var age: Int? } } +/// 验证是keyedcontainer容器下,使用SmartAny +extension Container_DictViewController { + + func getDict3() -> [String: Any] { + return [ + "dict2": NSNull(), + "dict3": 123, + "dict4": ["name": "mccc", "age": "20"], + + "dict6": NSNull(), + "dict7": 123, + "dict8": ["name": "mccc", "age": "20"], + ] + } + + + struct Model3: SmartCodable { + + // 无key + @SmartAny + var dict1: [String: Any] = [:] + // 值为null + @SmartAny + var dict2: [String: Any] = [:] + // 值类型错误 + @SmartAny + var dict3: [String: Any] = [:] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + @SmartAny + var dict4: [String: Any] = [:] + @SmartAny + var dict5: [String: Any]? + @SmartAny + var dict6: [String: Any]? + @SmartAny + var dict7: [String: Any]? + @SmartAny + var dict8: [String: Any]? + } +} + +/// 验证是keyedcontainer容器下,使用SmartAny +extension Container_DictViewController { + + func getDict4() -> [String: Any] { + return [ + "name": "Mccc", + "age": 18, + "model": [ + "name": "Mccc1", + "age": 188, + ] + ] + } + + + struct Model4: SmartCodable { + + var name: String = "" + var age: Int = 0 + + @SmartFlat + var model: FlatModel? + + } + + struct FlatModel: SmartCodable { + var name: String = "" + var age: Int = 0 + } +} diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_keyedViewController.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_keyedViewController.swift" new file mode 100644 index 0000000..1c5395a --- /dev/null +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_keyedViewController.swift" @@ -0,0 +1,192 @@ +// +// Container_keyedViewController.swift +// SmartCodable_Example +// +// Created by qixin on 2024/7/1. +// Copyright © 2024 CocoaPods. All rights reserved. +// + +import Foundation +import SmartCodable + +/// 兼容Int类型,只兼容String类型的int值。 +class Container_keyedViewController: BaseViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + +// let dict1 = getDict1() +// guard let feed = Model1.deserialize(from: dict1) else { return } +// smartPrint(value: feed) + + +// let dict2 = getDict2() +// guard let feed2 = Model2.deserialize(from: dict2) else { return } +// smartPrint(value: feed2) + + +// let dict3 = getDict3() +// guard let feed3 = Model3.deserialize(from: dict3) else { return } +// smartPrint(value: feed3) + + + let dict4 = getDict4() + guard let feed4 = Model4.deserialize(from: dict4) else { return } + smartPrint(value: feed4) + } + +} + + + + +/// 验证是keyedcontainer容器是字典的情况 +extension Container_keyedViewController { + + func getDict1() -> [String: Any] { + return [ + "dict2": NSNull(), + "dict3": 123, + "dict4": ["a": 1, "b": "2", "c": "3"], + + "dict6": NSNull(), + "dict7": 123, + "dict8": ["a": 1, "b": "2", "c": "3"] + ] + } + + + struct Model1: SmartCodable { + + // 无key + var dict1: [String: String] = [:] + // 值为null + var dict2: [String: String] = [:] + // 值类型错误 + var dict3: [String: String] = [:] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var dict4: [String: String] = [:] + + + var dict5: [String: String]? + var dict6: [String: String]? + var dict7: [String: String]? + var dict8: [String: String]? + } +} + + +/// 验证是keyedcontainer容器是Model的情况 +extension Container_keyedViewController { + + func getDict2() -> [String: Any] { + return [ + "model2": NSNull(), + "model3": 123, + "model4": ["name": "mccc", "age": "20"], + + "model6": NSNull(), + "model7": 123, + "model8": ["name": "mccc", "age": "20"], + ] + } + + + struct Model2: SmartCodable { + + // 无key + var model1 = SubModel() + // 值为null + var model2 = SubModel() + // 值类型错误 + var model3 = SubModel() + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var model4 = SubModel() + + + var model5: SubModel? + var model6: SubModel? + var model7: SubModel? + var model8: SubModel? + } + + struct SubModel: SmartCodable { + var name: String = "" + var age: Int? + } +} + +/// 验证是keyedcontainer容器下,使用SmartAny +extension Container_keyedViewController { + + func getDict3() -> [String: Any] { + return [ + "dict2": NSNull(), + "dict3": 123, + "dict4": ["name": "mccc", "age": "20"], + + "dict6": NSNull(), + "dict7": 123, + "dict8": ["name": "mccc", "age": "20"], + ] + } + + + struct Model3: SmartCodable { + + // 无key + @SmartAny + var dict1: [String: Any] = [:] + // 值为null + @SmartAny + var dict2: [String: Any] = [:] + // 值类型错误 + @SmartAny + var dict3: [String: Any] = [:] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + @SmartAny + var dict4: [String: Any] = [:] + + @SmartAny + var dict5: [String: Any]? + @SmartAny + var dict6: [String: Any]? + @SmartAny + var dict7: [String: Any]? + @SmartAny + var dict8: [String: Any]? + } +} + +/// 验证是keyedcontainer容器下,使用SmartAny +extension Container_keyedViewController { + + func getDict4() -> [String: Any] { + return [ + "name": "Mccc", + "age": 18, + "model": [ + "name": "Mccc1", + "age": 188, + ] + ] + } + + + struct Model4: SmartCodable { + + var name: String = "" + var age: Int = 0 + + @SmartFlat + var model: FlatModel? + + } + + struct FlatModel: SmartCodable { + var name: String = "" + var age: Int = 0 + } +} + diff --git "a/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_unKeyedViewController.swift" "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_unKeyedViewController.swift" new file mode 100644 index 0000000..0fb1aed --- /dev/null +++ "b/Example/SmartCodable/\346\265\213\350\257\225\347\224\250\344\276\213/\350\247\243\347\240\201/\346\225\260\346\215\256\346\265\213\350\257\225/Container_unKeyedViewController.swift" @@ -0,0 +1,257 @@ +// +// Container_unKeyedViewController.swift +// SmartCodable_Example +// +// Created by qixin on 2024/7/1. +// Copyright © 2024 CocoaPods. All rights reserved. +// + +import Foundation +import SmartCodable + +/// 兼容Int类型,只兼容String类型的int值。 +class Container_unKeyedViewController: BaseViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + +// let dict1 = getDict1() +// guard let feed = Model1.deserialize(from: dict1) else { return } +// smartPrint(value: feed) + + +// let dict2 = getDict2() +// guard let feed2 = Model2.deserialize(from: dict2) else { return } +// smartPrint(value: feed2) + + +// let dict3 = getDict3() +// guard let feed3 = Model3.deserialize(from: dict3) else { return } +// smartPrint(value: feed3) + + +// let dict4 = getDict4() +// guard let feed4 = Model4.deserialize(from: dict4) else { return } +// smartPrint(value: feed4) + + let dict5 = getDict5() + guard let feed5 = Model5.deserialize(from: dict5) else { return } + smartPrint(value: feed5) + } + +} + +/// 验证是unkeyedcontainer容器是数组的情况 +extension Container_unKeyedViewController { + + func getDict1() -> [String: Any] { + return [ + "arr2": NSNull(), + "arr3": 123, + "arr4": [1, "2", 3], + "arr5": [1, "2", 3, NSNull()], + + "arr7": NSNull(), + "arr8": 123, + "arr9": [1, "2", 3], + "arr10": [1, "2", 3, NSNull()], + ] + } + + + struct Model1: SmartCodable { + + // 无key + var arr1: [String] = [] + // 值为null + var arr2: [String] = [] + // 值类型错误 + var arr3: [String] = [] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var arr4: [String] = [] + var arr5: [String] = [] + + + + var arr6: [String]? + var arr7: [String]? + var arr8: [String]? + var arr9: [String]? + var arr10: [String]? + } +} + +/// 验证是unkeyedcontainer容器是数组的情况 +extension Container_unKeyedViewController { + + func getDict2() -> [String: Any] { + return [ + "arr2": NSNull(), + "arr3": 123, + "arr4": [1, "2", 3], + "arr5": [1, "2", 3, NSNull()], + + "arr7": NSNull(), + "arr8": 123, + "arr9": [1, "2", 3], + "arr10": [1, "2", 3, NSNull()], + ] + } + + + + struct Model2: SmartCodable { + + // 无key + var arr1: [String?] = [] + // 值为null + var arr2: [String?] = [] + // 值类型错误 + var arr3: [String?] = [] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var arr4: [String?] = [] + var arr5: [String?] = [] + + + var arr6: [String?]? + var arr7: [String?]? + var arr8: [String?]? + var arr9: [String?]? + var arr10: [String?]? + + } +} + +/// 验证是unkeyedcontainer容器是[Model]的情况 +extension Container_unKeyedViewController { + + func getDict3() -> [String: Any] { + return [ + "arr2": NSNull(), + "arr3": 123, + "arr4": [["name": "Mccc", "age": "20"]], + "arr5": [["name": "Mccc", "age": "20"], NSNull()], + + "arr7": NSNull(), + "arr8": 123, + "arr9": [["name": "Mccc", "age": "20"]], + "arr10": [["name": "Mccc", "age": "20"], NSNull()], + + ] + } + + + + struct Model3: SmartCodable { + + // 无key + var arr1: [SubModel] = [] + // 值为null + var arr2: [SubModel] = [] + // 值类型错误 + var arr3: [SubModel] = [] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var arr4: [SubModel] = [] + var arr5: [SubModel] = [] + + + var arr6: [SubModel]? + var arr7: [SubModel]? + var arr8: [SubModel]? + var arr9: [SubModel]? + var arr10: [SubModel]? + + } + + struct SubModel: SmartCodable { + var name: String = "" + var age: Int? + } +} + +/// 验证是unkeyedcontainer容器是[Model]的情况 +extension Container_unKeyedViewController { + + func getDict4() -> [String: Any] { + return [ + "arr2": NSNull(), + "arr3": 123, + "arr4": [["name": "Mccc", "age": "20"]], + "arr5": [["name": "Mccc", "age": "20"], NSNull()], + + "arr7": NSNull(), + "arr8": 123, + "arr9": [["name": "Mccc", "age": "20"]], + "arr10": [["name": "Mccc", "age": "20"], NSNull()], + + ] + } + + struct Model4: SmartCodable { + + // 无key + var arr1: [SubModel?] = [] + // 值为null + var arr2: [SubModel?] = [] + // 值类型错误 + var arr3: [SubModel?] = [] + // 元素类型支持类型转换,如果转换失败,则返回初始化值 + var arr4: [SubModel?] = [] + var arr5: [SubModel?] = [] + + var arr6: [SubModel?]? + var arr7: [SubModel?]? + var arr8: [SubModel?]? + var arr9: [SubModel?]? + var arr10: [SubModel?]? + } +} + +/// 验证是unkeyedcontainer容器 SmartAny 修饰的情况 +extension Container_unKeyedViewController { + + func getDict5() -> [String: Any] { + return [ +// "arr2": NSNull(), +// "arr3": 123, +// "arr4": [1, 2, "3"], + "arr5": ["3", NSNull()], +// +// "arr7": NSNull(), +// "arr8": 123, +// "arr9": [1, 2, "3"], +// "arr10": ["3", NSNull()], + ] + } + + struct Model5: SmartCodable { + +// // 无key +// @SmartAny +// var arr1: [Any] = [] +// // 值为null +// @SmartAny +// var arr2: [Any] = [] +// // 值类型错误 +// @SmartAny +// var arr3: [Any] = [] +// // 元素类型支持类型转换,如果转换失败,则返回初始化值 +// @SmartAny +// var arr4: [Any] = [] + @SmartAny + var arr5: [String] = [] +// +// @SmartAny +// var arr6: [Any]? +// @SmartAny +// var arr7: [Any]? +// @SmartAny +// var arr8: [Any]? +// @SmartAny +// var arr9: [Any]? +// @SmartAny +// var arr10: [String?]? + + } +} diff --git a/SmartCodable.podspec b/SmartCodable.podspec index de5f1ef..4f57820 100644 --- a/SmartCodable.podspec +++ b/SmartCodable.podspec @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.name = 'SmartCodable' - s.version = '4.0.4' + s.version = '4.1.0' s.summary = '数据解析库' s.homepage = 'https://github.com/intsig171' diff --git a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+KeyedContainer.swift b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+KeyedContainer.swift index 02466d2..c50da0b 100644 --- a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+KeyedContainer.swift +++ b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+KeyedContainer.swift @@ -439,14 +439,17 @@ extension JSONDecoderImpl.KeyedContainer { func decodeIfPresent(_ type: T.Type, forKey key: K) throws -> T? where T: Decodable { + guard let value = try? getValue(forKey: key) else { + return optionalDecode(forKey: key) + } + + if type == CGFloat.self { return try decodeIfPresent(CGFloat.self, forKey: key) as? T } - if let value = try? getValue(forKey: key) { - if let decoded = impl.cache.tranform(value: value, for: key) as? T { - return decoded - } + if let decoded = impl.cache.tranform(value: value, for: key) as? T { + return decoded } guard let newDecoder = try? decoderForKeyCompatibleForJson(key, type: type) else { @@ -471,13 +474,22 @@ extension JSONDecoderImpl.KeyedContainer { fileprivate func optionalDecode(forKey key: Key) -> T? { guard let value = try? getValue(forKey: key) else { + SmartLog.createLog(impl: impl, forKey: key, value: nil, type: T.self) + if let initializer: T = impl.cache.getValue(forKey: key) { + return initializer + } return nil } + SmartLog.createLog(impl: impl, forKey: key, value: value, type: T.self) - guard let decoded = Patcher.convertToType(from: value.peel) else { + + if let decoded = Patcher.convertToType(from: value.peel) { + return decoded + } else if let initializer: T = impl.cache.getValue(forKey: key) { + return initializer + } else { return nil } - return decoded } diff --git a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+UnkeyedContainer.swift b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+UnkeyedContainer.swift index 9ee5148..d5df162 100644 --- a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+UnkeyedContainer.swift +++ b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl+UnkeyedContainer.swift @@ -76,10 +76,6 @@ extension JSONDecoderImpl { options: self.impl.options ) } - - - - } } diff --git a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl.swift b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl.swift index d21c400..d848868 100644 --- a/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl.swift +++ b/SmartCodable/Classes/JSONDecoder/Decoder/Impl/JSONDecoderImpl.swift @@ -11,14 +11,14 @@ import Foundation struct JSONDecoderImpl { let codingPath: [CodingKey] let userInfo: [CodingUserInfoKey: Any] - + let json: JSONValue let options: SmartJSONDecoder._Options /// Records the initialization values of the properties in the keyed container. var cache: DecodingCache - + init(userInfo: [CodingUserInfoKey: Any], from json: JSONValue, codingPath: [CodingKey], options: SmartJSONDecoder._Options) { self.userInfo = userInfo self.codingPath = codingPath @@ -34,48 +34,73 @@ struct JSONDecoderImpl { // and when the exception is handled, the initial value can be obtained. extension JSONDecoderImpl: Decoder { func container(keyedBy key: Key.Type) throws -> - KeyedDecodingContainer where Key: CodingKey { - var newDictionary: [String: JSONValue] = [:] + KeyedDecodingContainer where Key: CodingKey { + switch self.json { case .object(let dictionary): - newDictionary = dictionary + let container = KeyedContainer( + impl: self, + codingPath: codingPath, + dictionary: dictionary + ) + return KeyedDecodingContainer(container) case .string(let string): // json string modeling compatibility if let dict = string.toJSONObject() as? [String: Any], let dictionary = JSONValue.make(dict)?.object { - newDictionary = dictionary + let container = KeyedContainer( + impl: self, + codingPath: codingPath, + dictionary: dictionary + ) + return KeyedDecodingContainer(container) } + case .null: + throw DecodingError.valueNotFound([String: JSONValue].self, DecodingError.Context( + codingPath: self.codingPath, + debugDescription: "Cannot get keyed decoding container -- found null value instead" + )) default: break } - let container = KeyedContainer( - impl: self, - codingPath: codingPath, - dictionary: newDictionary - ) - return KeyedDecodingContainer(container) + + throw DecodingError.typeMismatch([String: JSONValue].self, DecodingError.Context( + codingPath: self.codingPath, + debugDescription: "Expected to decode \([String: JSONValue].self) but found \(self.json.debugDataTypeDescription) instead." + )) } - + func unkeyedContainer() throws -> UnkeyedDecodingContainer { - var newArray: [JSONValue] = [] switch self.json { case .array(let array): - newArray = array + return UnkeyedContainer( + impl: self, + codingPath: self.codingPath, + array: array + ) case .string(let string): // json字符串的模型化兼容 if let arr = string.toJSONObject() as? [Any], let array = JSONValue.make(arr)?.array { - newArray = array + return UnkeyedContainer( + impl: self, + codingPath: self.codingPath, + array: array + ) } + case .null: + throw DecodingError.valueNotFound([String: JSONValue].self, DecodingError.Context( + codingPath: self.codingPath, + debugDescription: "Cannot get unkeyed decoding container -- found null value instead" + )) default: break } - return UnkeyedContainer( - impl: self, + throw DecodingError.typeMismatch([JSONValue].self, DecodingError.Context( codingPath: self.codingPath, - array: newArray - ) + debugDescription: "Expected to decode \([JSONValue].self) but found \(self.json.debugDataTypeDescription) instead." + )) } - + func singleValueContainer() throws -> SingleValueDecodingContainer { SingleValueContainer( impl: self, @@ -91,27 +116,27 @@ extension JSONDecoderImpl: Decoder { internal struct _JSONKey: CodingKey { public var stringValue: String public var intValue: Int? - + public init?(stringValue: String) { self.stringValue = stringValue self.intValue = nil } - + public init?(intValue: Int) { self.stringValue = "\(intValue)" self.intValue = intValue } - + public init(stringValue: String, intValue: Int?) { self.stringValue = stringValue self.intValue = intValue } - + internal init(index: Int) { self.stringValue = "Index \(index)" self.intValue = index } - + internal static let `super` = _JSONKey(stringValue: "super")! } diff --git a/SmartCodable/Classes/Log/SmartLog.swift b/SmartCodable/Classes/Log/SmartLog.swift index c622bc3..ad40995 100644 --- a/SmartCodable/Classes/Log/SmartLog.swift +++ b/SmartCodable/Classes/Log/SmartLog.swift @@ -77,9 +77,6 @@ extension SmartLog { impl: JSONDecoderImpl, error: DecodingError) { let className = impl.cache.topSnapshot?.typeName ?? "" - var path = impl.codingPath -// path.append(key) - var address = "" if let parsingMark = CodingUserInfoKey.parsingMark { address = impl.userInfo[parsingMark] as? String ?? "" diff --git a/SmartCodable/Classes/SmartType/SmartAny/SmartAny.swift b/SmartCodable/Classes/SmartType/SmartAny/SmartAny.swift index 712f29f..e408926 100644 --- a/SmartCodable/Classes/SmartType/SmartAny/SmartAny.swift +++ b/SmartCodable/Classes/SmartType/SmartAny/SmartAny.swift @@ -29,9 +29,7 @@ public struct SmartAny: Codable { return } } - - - + if let new = try? decoder.unwrap(as: SmartAnyImpl.self), let peel = new.peel as? T { self = .init(wrappedValue: peel) @@ -41,9 +39,6 @@ public struct SmartAny: Codable { codingPath: decoder.codingPath, debugDescription: "Expected \(Self.self) value,but an exception occurred!") ) } - - - } public func encode(to encoder: Encoder) throws { diff --git a/SmartCodable/Classes/SmartType/SmartFlat.swift b/SmartCodable/Classes/SmartType/SmartFlat.swift index 792c8d5..8b21c87 100644 --- a/SmartCodable/Classes/SmartType/SmartFlat.swift +++ b/SmartCodable/Classes/SmartType/SmartFlat.swift @@ -16,19 +16,11 @@ public struct SmartFlat: Codable { } public init(from decoder: Decoder) throws { - do { wrappedValue = try T(from: decoder) } catch { - - wrappedValue = try Patcher.defaultForType() -// print(error) - -// throw error } - - } public func encode(to encoder: Encoder) throws {