You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -310,7 +310,7 @@ Convert between JSON values and custom types
310
310
|**SmartDateFormatTransformer**| String | Date | Uses DateFormatter for custom date string formats |
311
311
|**SmartURLTransformer**| String | URL | Converts strings to URLs with optional encoding and prefixing |
312
312
313
-
```
313
+
```swift
314
314
structModel: SmartCodable {
315
315
316
316
...
@@ -329,7 +329,7 @@ struct Model: SmartCodable {
329
329
330
330
If you need additional parsing rules, **Transformer** will implement them yourself. Follow **ValueTransformable** to implement the requirements of the protocol.
331
331
332
-
```
332
+
```swift
333
333
publicprotocolValueTransformable {
334
334
associatedtypeObject
335
335
associatedtypeJSON
@@ -344,7 +344,7 @@ public protocol ValueTransformable {
@@ -467,7 +467,7 @@ if let model = PublishedModel.deserialize(from: dict) {
467
467
468
468
Adds Codable support for UIColor/NSColor using hex string encoding/decoding.
469
469
470
-
```
470
+
```swift
471
471
structModel: SmartCodable {
472
472
@SmartHexColor
473
473
var color: UIColor?
@@ -494,7 +494,7 @@ If you need inheritance support, annotate your subclass with `@SmartSubclass`.
494
494
495
495
#### 4.1 Basic Usage
496
496
497
-
```
497
+
```swift
498
498
classBaseModel: SmartCodable {
499
499
var name: String=""
500
500
requiredinit() { }
@@ -510,7 +510,7 @@ class StudentModel: BaseModel {
510
510
511
511
Just implement it directly—no need for the `override` keyword.
512
512
513
-
```
513
+
```swift
514
514
classBaseModel: SmartCodable {
515
515
var name: String=""
516
516
requiredinit() { }
@@ -532,7 +532,7 @@ class StudentModel: BaseModel {
532
532
533
533
#### 4.3 Parent Class Implements Protocol Method
534
534
535
-
```
535
+
```swift
536
536
classBaseModel: SmartCodable {
537
537
var name: String=""
538
538
requiredinit() { }
@@ -555,7 +555,7 @@ A few things to note:
555
555
- The protocol method in the parent class must be marked with `class`.
556
556
- The subclass should call the parent class's implementation.
557
557
558
-
```
558
+
```swift
559
559
classBaseModel: SmartCodable {
560
560
var name: String=""
561
561
requiredinit() { }
@@ -593,7 +593,7 @@ SmartCodable automatically handles string-encoded JSON values during decoding, s
593
593
-**Recursive Mapping**: Applies `mappingForKey()` rules to parsed nested structures
594
594
-**Type Inference**: Determines parsing strategy (object/array) based on property type
595
595
596
-
```
596
+
```swift
597
597
structModel: SmartCodable {
598
598
var hobby: Hobby?
599
599
var hobbys: [Hobby]?
@@ -617,7 +617,7 @@ guard let model = Model.deserialize(from: dict) else { return }
617
617
618
618
If attribute resolution fails, SmartCodable performs compatibility processing for thrown exceptions. Ensure that the entire parsing is not interrupted. Even better, you don't have to do anything about it.
619
619
620
-
```
620
+
```swift
621
621
let dict = [
622
622
"number1":"123",
623
623
"number2":"Mccc",
@@ -656,7 +656,7 @@ This can greatly improve the analytical efficiency.
656
656
657
657
To be convertable, An `enum` must conform to `SmartCaseDefaultable` protocol. Nothing special need to do now.
658
658
659
-
```
659
+
```swift
660
660
structStudent: SmartCodable {
661
661
var name: String=""
662
662
var sex: Sex = .man
@@ -675,7 +675,7 @@ let model = Student.deserialize(from: json)
675
675
676
676
Make the enumeration follow **SmartAssociatedEnumerable**。Override the **mappingForValue** method and take over the decoding process yourself.
0 commit comments