Skip to content

Commit 5c8839b

Browse files
author
Mccc
committed
发布V4.2.0
1 parent 74c78e5 commit 5c8839b

6 files changed

Lines changed: 43 additions & 10 deletions

File tree

Document/README/Usages.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ class Model: SmartDecodable {
511511

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

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

516518
```
517519
let jsonString = """
@@ -539,7 +541,38 @@ struct SubModel: SmartCodable {
539541
}
540542
```
541543

542-
544+
2. 重写`init(from decoder: Decoder) ` 方法,接管解析。
545+
546+
```
547+
class BaseModel: SmartCodable {
548+
var name: String = ""
549+
var age: Int = 0
550+
551+
enum CodingKeys: CodingKey {
552+
case name
553+
case age
554+
}
555+
required init() { }
556+
}
557+
558+
class SubModel: BaseModel {
559+
var nickName: String = ""
560+
enum CodingKeys: CodingKey {
561+
case nickName
562+
}
563+
required init(from decoder: Decoder) throws {
564+
try super.init(from: decoder)
565+
let container = try decoder.container(keyedBy: CodingKeys.self)
566+
self.nickName = try container.decode(String.self, forKey: .nickName)
567+
}
568+
569+
required init() {
570+
super.init()
571+
}
572+
}
573+
```
574+
575+
543576

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

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- FBSnapshotTestCase/SwiftSupport (2.1.4):
99
- FBSnapshotTestCase/Core
1010
- HandyJSON (5.0.0-beta.1)
11-
- SmartCodable (4.1.11-beta.3)
11+
- SmartCodable (4.2.0)
1212
- SnapKit (5.6.0)
1313

1414
DEPENDENCIES:
@@ -39,7 +39,7 @@ SPEC CHECKSUMS:
3939
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
4040
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
4141
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
42-
SmartCodable: 5429462702dd8ac32fb664d98c367120cd331d37
42+
SmartCodable: e1b30d724aa0c1c82964a8cef06709dc93154f4f
4343
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
4444

4545
PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f

Example/Pods/Local Podspecs/SmartCodable.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartCodable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
Pod::Spec.new do |s|
1414
s.name = 'SmartCodable'
15-
s.version = '4.1.11-beta.4'
15+
s.version = '4.2.0'
1616
s.summary = '数据解析库'
1717

1818
s.homepage = 'https://github.com/intsig171'

0 commit comments

Comments
 (0)