Skip to content

Commit

Permalink
支持更多Int族的类型转换
Browse files Browse the repository at this point in the history
  • Loading branch information
intsig171 committed May 13, 2024
1 parent 267bb2c commit 0abd7a4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 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.4.1)
- SmartCodable (3.4.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: 9c9941a8303a8bedb16884a1c6efb27c91851126
SmartCodable: a99b61311a03dcbeab24d680ab684f61db1d76ea
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.

6 changes: 3 additions & 3 deletions Example/SmartCodable/TestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestViewController: BaseViewController {
super.viewDidLoad()

let dict: [String: Any] = [
"age": 10,
"age": "10",
"name": "Mccc",
"area": "su zhou"
]
Expand All @@ -44,8 +44,8 @@ class TestViewController: BaseViewController {
}
struct Home: SmartCodable {
var name: String = ""
@IgnoredKey
var age: [Any] = ["1"]

var age: Int64 = 0
@IgnoredKey
var area: String = "area"
}
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.4.1'
s.version = '3.4.2'
s.summary = '数据解析库'

s.homepage = 'https://github.com/intsig171'
Expand Down
69 changes: 69 additions & 0 deletions SmartCodable/Classes/JSONDecoder/Patcher/Patcher+Transformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,75 @@ extension Int: TypeTransformable {
}
}

extension Int8: TypeTransformable {
static func transformValue(from value: Any) -> Int8? {
switch value {
case let temp as String:
return Int8(temp)
case let temp as Float:
return Int8(temp)
case let temp as Double:
return Int8(temp)
case let temp as CGFloat:
return Int8(temp)
default:
return nil
}
}
}

extension Int16: TypeTransformable {
static func transformValue(from value: Any) -> Int16? {
switch value {
case let temp as String:
return Int16(temp)
case let temp as Float:
return Int16(temp)
case let temp as Double:
return Int16(temp)
case let temp as CGFloat:
return Int16(temp)
default:
return nil
}
}
}


extension Int32: TypeTransformable {
static func transformValue(from value: Any) -> Int32? {
switch value {
case let temp as String:
return Int32(temp)
case let temp as Float:
return Int32(temp)
case let temp as Double:
return Int32(temp)
case let temp as CGFloat:
return Int32(temp)
default:
return nil
}
}
}

extension Int64: TypeTransformable {
static func transformValue(from value: Any) -> Int64? {
switch value {
case let temp as String:
return Int64(temp)
case let temp as Float:
return Int64(temp)
case let temp as Double:
return Int64(temp)
case let temp as CGFloat:
return Int64(temp)
default:
return nil
}
}
}


extension Float: TypeTransformable {
static func transformValue(from value: Any) -> Float? {
Expand Down

0 comments on commit 0abd7a4

Please sign in to comment.