Skip to content

Commit

Permalink
完成Container的优化
Browse files Browse the repository at this point in the history
  • Loading branch information
intsig171 committed Jul 3, 2024
1 parent f0e587a commit bbe4761
Show file tree
Hide file tree
Showing 23 changed files with 861 additions and 172 deletions.
Binary file modified Document/TestCaseSpecification.xmind
Binary file not shown.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -39,7 +39,7 @@ SPEC CHECKSUMS:
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
SmartCodable: 91f469249cf9cd8c1ef4777bffe902e167293846
SmartCodable: 04f61a30bd6567fc15b71e718e1aee4766956e55
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25

PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f
Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SmartCodable.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions Example/SmartCodable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -178,10 +180,12 @@
99328D982B5138210074036A /* area.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = area.json; sourceTree = "<group>"; };
993822D32B5E52C0007D3268 /* BaseTwoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTwoViewController.swift; sourceTree = "<group>"; };
9955576D2BE0DCC6005F9ABD /* Introduce_10ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Introduce_10ViewController.swift; sourceTree = "<group>"; };
9955AC4F2C32B08700D25466 /* Container_keyedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container_keyedViewController.swift; sourceTree = "<group>"; };
9955AC512C32B0FD00D25466 /* Container_unKeyedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container_unKeyedViewController.swift; sourceTree = "<group>"; };
9956B9B82BD92D1900C711F5 /* DecodingArrayLogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingArrayLogViewController.swift; sourceTree = "<group>"; };
9957743A2BFD95E4003613C5 /* SpecialData_ColorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpecialData_ColorViewController.swift; sourceTree = "<group>"; };
995E03BC2C12F727009E1E5B /* Encode_IgnoredKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_IgnoredKeyViewController.swift; sourceTree = "<group>"; };
995E03BF2C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_ContainerViewcontroller.swift; sourceTree = "<group>"; };
995E03BF2C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_ContainerDictViewcontroller.swift; sourceTree = "<group>"; };
995E03C12C182C68009E1E5B /* Introduce_11ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Introduce_11ViewController.swift; sourceTree = "<group>"; };
99675FD62B3EC930006C83EC /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
99675FD82B3EC930006C83EC /* NSDictionary+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSDictionary+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -439,7 +443,7 @@
995E03BE2C12F926009E1E5B /* Container */ = {
isa = PBXGroup;
children = (
995E03BF2C12F93C009E1E5B /* Encode_ContainerViewcontroller.swift */,
995E03BF2C12F93C009E1E5B /* Encode_ContainerDictViewcontroller.swift */,
);
path = Container;
sourceTree = "<group>";
Expand Down Expand Up @@ -600,6 +604,8 @@
99A494E52B9028EB00393193 /* 数据测试 */ = {
isa = PBXGroup;
children = (
9955AC4F2C32B08700D25466 /* Container_keyedViewController.swift */,
9955AC512C32B0FD00D25466 /* Container_unKeyedViewController.swift */,
99CABA2A2B916DD30070DED0 /* BaseData */,
99CABA2B2B916DE40070DED0 /* Container */,
99D945882B91C4D500CC6470 /* SpecialData */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand Down
87 changes: 65 additions & 22 deletions Example/SmartCodable/Test2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
37 changes: 19 additions & 18 deletions Example/SmartCodable/Test3ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}

Expand Down
50 changes: 39 additions & 11 deletions Example/SmartCodable/TestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
}
}
Original file line number Diff line number Diff line change
@@ -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]?
}
}

This file was deleted.

Loading

0 comments on commit bbe4761

Please sign in to comment.