Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
intsig171 committed Aug 12, 2024
1 parent 83c85f0 commit 26d852f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 54 deletions.
31 changes: 9 additions & 22 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

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

36 changes: 14 additions & 22 deletions Example/SmartCodable/Test2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,25 @@ class Test2ViewController: BaseViewController {

override func viewDidLoad() {
super.viewDidLoad()

let subModel = SubModel()
let model = Model(type: 2, data: subModel)


let json = model.toJSONString()
let dict: [String: Any] = [
"nick_name": "Mccc"
]

print(json)
}

class Model: SmartCodable {
init(type: Int, data: Any) {
self.type = type
self.data = data
}
let option = SmartDecodingOption.key(.fromSnakeCase)
guard let model = Model.deserialize(from: dict, options: [option]) else { return }

var type: Int?
smartPrint(value: model)

@SmartAny
var data: Any?

required init() { }
let string = model.toJSONString(useMappedKeys: false)
print(string)
}


class SubModel: SmartCodable {
var name: String = "mccc"
required init() { }

struct Model: SmartCodable {
var nickName: String = ""


}
}
12 changes: 2 additions & 10 deletions SmartCodable/Classes/JSONDecoder/Patcher/Patcher+Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Foundation
extension Patcher {
struct Provider {
static func defaultValue() throws -> T {


if let value = T.self as? Defaultable.Type {
return value.defaultValue as! T
Expand All @@ -24,10 +23,8 @@ extension Patcher {
}
} else if let object = T.self as? any SmartAssociatedEnumerable.Type {
return object.defaultCase as! T
} else {
throw DecodingError.valueNotFound(Self.self, DecodingError.Context(
codingPath: [], debugDescription: "Expected \(Self.self) value,but an exception occurred!Please report this issue(请上报该问题)"))
}

throw DecodingError.valueNotFound(Self.self, DecodingError.Context(
codingPath: [], debugDescription: "Expected \(Self.self) value,but an exception occurred!Please report this issue(请上报该问题)"))
}
Expand Down Expand Up @@ -59,12 +56,9 @@ extension Array: Defaultable {
}

extension Dictionary: Defaultable {
static var defaultValue: Dictionary<Key, Value> {
return [:]
}
static var defaultValue: Dictionary<Key, Value> { return [:] }
}


extension String: Defaultable {
static var defaultValue: String { "" }
}
Expand All @@ -86,7 +80,6 @@ extension CGFloat: Defaultable {
static var defaultValue: CGFloat { 0.0 }
}


extension Int: Defaultable {
static var defaultValue: Int { 0 }
}
Expand All @@ -108,7 +101,6 @@ extension Int64: Defaultable {
}



extension UInt: Defaultable {
static var defaultValue: UInt { 0 }
}
Expand Down

0 comments on commit 26d852f

Please sign in to comment.