Skip to content

Commit

Permalink
v3.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
intsig171 committed Apr 22, 2024
1 parent b74be25 commit 78aea98
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 92 deletions.
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 (3.3.1)
- SmartCodable (3.3.2)
- SnapKit (5.6.0)
- SQLiteRepairKit (1.3.0):
- WCDBOptimizedSQLCipher (~> 1.3.0)
Expand Down Expand Up @@ -49,7 +49,7 @@ SPEC CHECKSUMS:
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
SmartCodable: 3d782ddbe0d157d3c882c8e446030230a59aabe4
SmartCodable: 44b817e837231549b1aae22f50b275eef6d09ba8
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
SQLiteRepairKit: a66145aadae91886c800f75e16f5cc6476af1a93
WCDB.swift: 39e28fe29b5a3bf2927d9fb9218978f19bd49ff0
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.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class Introduce_8ViewController: BaseCompatibilityViewController {
super.viewDidLoad()


let dict = [
"number": "one",
let dict: [String: Any] = [
// "number": "one",
"number1": [],
"number2": "one",

"sex": "haha"
]

guard let model = CompatibleEnum.deserialize(from: dict) else { return }
print(model)
print("model = \(model)")

// 如果进入兼容逻辑,json值将被修改,无法恢复。
guard let transformDict = model.toDictionary() else { return }
Expand All @@ -40,7 +43,11 @@ extension Introduce_8ViewController {
struct CompatibleEnum: SmartCodable {

init() { }
var number: NumberType?
var number: NumberType = .two
var number1: NumberType = .two
var number2: NumberType = .two


var sex: Sex = .man

static func mappingForValue() -> [SmartValueTransformer]? {
Expand Down
106 changes: 77 additions & 29 deletions Example/SmartCodable/Test2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,94 @@ class Test2ViewController: BaseViewController {
super.viewDidLoad()

let dict: [String: Any] = [
"cgFloat": 20.0

"type1": [],
"type2": "3",

"any1": NSNull(),
"any2": "3",


"dict1": [],
"dict2": [
"one": 1,
"two": "2"
],

"arr1": 1,
"arr2": ["abc"],

"color1": "666666",
"color2": "000000"
]

guard let model = Model.deserialize(from: dict) else { return }
guard let model = Family.deserialize(from: dict) else { return }
print(model)

// print(UIColor.white)

}


struct Model: SmartCodable {
var cgFloat: CGFloat = 0.0

}


extension Test2ViewController {

enum RealtionEnum: SmartAssociatedEnumerable {
static var defaultCase: RealtionEnum = .one
case one
case two

}

enum FamilyType: String, SmartCaseDefaultable {
static var defaultCase: FamilyType = .new

static func mappingForValue() -> [SmartValueTransformer]? {
[
CodingKeys.cgFloat <--- CGFloatTransformer()
]
}
case new = "1"
case old = "2"
case middle = "3"
}
}

/** 覆盖测试情况
* [完成]枚举
* [完成]SmartAny
* [完成][String: SmartAny]
* [完成][SmartAny]
* [完成]SmartColor
* URL
*/
struct Family: SmartCodable {

// var rela: RealtionEnum = .one
// var rela1: RealtionEnum = .two

// var type: FamilyType = .old
// var type1: FamilyType = .old
// var type2: FamilyType = .old

// var any: SmartAny = .string("1")
// var any1: SmartAny?
// var any2: SmartAny = .string("3")

// var dict: [String: SmartAny] = ["one": SmartAny.string("1")]
// var dict1: [String: SmartAny] = ["two": SmartAny.string("2")]
// var dict2: [String: SmartAny] = ["three": SmartAny.string("3")]

// var arr : [SmartAny] = [SmartAny.number(1)]
// var arr1 : [SmartAny] = [SmartAny.number(2)]
// var arr2 : [SmartAny] = [SmartAny.number(3)]

// var color: SmartColor = .color(.white)
// var color1: SmartColor = .color(.black)
// var color2: SmartColor = .color(.red)


extension Test2ViewController {
struct CGFloatTransformer: ValueTransformable {
func transformFromJSON(_ value: Any?) -> CGFloat? {
if let temp = value as? CGFloat {
print(100 + temp)

return 100 + temp


}
return nil
}

func transformToJSON(_ value: CGFloat?) -> CGFloat? {
return value
}

typealias Object = CGFloat
typealias JSON = CGFloat
// var dict: SmartAny?
// var color: SmartColor = .color(UIColor.red)
// var url: URL?
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CaseTwo_ArrayNestDictViewController: BaseCompatibilityViewController {
],
"love": [
"name": NSNull(),
// "time": 4
"time": 4
],
"son": nil
],
Expand All @@ -43,7 +43,7 @@ class CaseTwo_ArrayNestDictViewController: BaseCompatibilityViewController {
],
"love": [
"name": NSNull(),
// "time": 4
"time": 4
],
"son": nil
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class CaseTwo_DictNestDictViewController: BaseCompatibilityViewController {
super.viewDidLoad()

let dict: [String: Any] = [
// "name": "father",
"name": "father",
"age": 30,
// "love": [
// "name": "basketball",
// "time": 10
// ],
// "son": [
// "name": "son",
// "age": 4,
// "love": [
// "name": "sleep",
// "time": 4
// ],
// ]
"love": [
"name": "basketball",
"time": 10
],
"son": [
"name": "son",
"age": 4,
"love": [
"name": "sleep",
"time": 4
],
]
]


Expand Down
2 changes: 1 addition & 1 deletion SmartCodable.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Pod::Spec.new do |s|
s.name = 'SmartCodable'
s.version = '3.3.1'
s.version = '3.3.2'
s.summary = '数据解析库'

s.homepage = 'https://github.com/intsig171'
Expand Down
Loading

0 comments on commit 78aea98

Please sign in to comment.