Skip to content

Commit

Permalink
发布V4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mccc committed Sep 27, 2024
1 parent 74c78e5 commit 5c8839b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
37 changes: 35 additions & 2 deletions Document/README/Usages.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ class Model: SmartDecodable {

Inheritance does not have a particularly good implementation in Codable, but SmartCodable provides a combination (@SmartFlat) that indirectly implements inheritance requirements.

继承在Codable中没有特别好的实现方案, SmartCodable提供了组合方式(@SmartFlat)用来间接实现继承的需求。
继承在Codable中没有特别好的实现方案, 这里提供两种方案:

1. SmartCodable提供了组合方式(@SmartFlat)用来间接实现继承的需求。

```
let jsonString = """
Expand Down Expand Up @@ -539,7 +541,38 @@ struct SubModel: SmartCodable {
}
```


2. 重写`init(from decoder: Decoder) ` 方法,接管解析。

```
class BaseModel: SmartCodable {
var name: String = ""
var age: Int = 0
enum CodingKeys: CodingKey {
case name
case age
}
required init() { }
}
class SubModel: BaseModel {
var nickName: String = ""
enum CodingKeys: CodingKey {
case nickName
}
required init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
self.nickName = try container.decode(String.self, forKey: .nickName)
}
required init() {
super.init()
}
}
```



### Update Existing Model(更新现有模型)

Expand Down
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.1.11-beta.3)
- SmartCodable (4.2.0)
- SnapKit (5.6.0)

DEPENDENCIES:
Expand Down Expand Up @@ -39,7 +39,7 @@ SPEC CHECKSUMS:
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
SmartCodable: 5429462702dd8ac32fb664d98c367120cd331d37
SmartCodable: e1b30d724aa0c1c82964a8cef06709dc93154f4f
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.

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 = '4.1.11-beta.4'
s.version = '4.2.0'
s.summary = '数据解析库'

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

0 comments on commit 5c8839b

Please sign in to comment.