Skip to content

Commit f2b7cc0

Browse files
authored
Merge pull request #115 from vsouza/chore/add-sintax-highlight-readme
Add syntax highlight in README file.
2 parents 95b574f + 73a4015 commit f2b7cc0

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ If you are using HandyJSON and would like to replace it, follow this link.
146146

147147
### 📦 Swift Package Manager
148148

149-
```
149+
```swift
150150
dependencies: [
151151
.package(url: "https://github.com/iAmMccc/SmartCodable.git", from: "xxx")
152152
]
@@ -156,7 +156,7 @@ dependencies: [
156156

157157
### Usage Examples
158158

159-
```
159+
```swift
160160
import SmartCodable
161161

162162
struct User: SmartCodable {
@@ -176,7 +176,7 @@ To support deserialization from JSON, a class/struct need to conform to 'SmartCo
176176

177177
To conform to 'SmartCodable', a class need to implement an empty initializer.
178178

179-
```
179+
```swift
180180
class BasicTypes: SmartCodable {
181181
var int: Int = 2
182182
var doubleOptional: Double?
@@ -187,7 +187,7 @@ let model = BasicTypes.deserialize(from: json)
187187

188188
For struct, since the compiler provide a default empty initializer, we use it for free.
189189

190-
```
190+
```swift
191191
struct BasicTypes: SmartCodable {
192192
var int: Int = 2
193193
var doubleOptional: Double?
@@ -203,7 +203,7 @@ let model = BasicTypes.deserialize(from: json)
203203

204204
Only types conforming to `SmartCodable` (or `[SmartCodable]` for arrays) can use these methods
205205

206-
```
206+
```swift
207207
public static func deserialize(from dict: [String: Any]?, designatedPath: String? = nil, options: Set<SmartDecodingOption>? = nil) -> Self?
208208

209209
public static func deserialize(from json: String?, designatedPath: String? = nil, options: Set<SmartDecodingOption>? = nil) -> Self?
@@ -246,7 +246,7 @@ Model.deserialize(from: json, designatedPath: "data.user.info")
246246

247247
**3. Decoding Strategies (`options`)**
248248

249-
```
249+
```swift
250250
let options: Set<SmartDecodingOption> = [
251251
.key(.convertFromSnakeCase),
252252
.date(.iso8601),
@@ -269,7 +269,7 @@ let options: Set<SmartDecodingOption> = [
269269

270270
#### 2.2 Post-processing callback invoked after successful decoding
271271

272-
```
272+
```swift
273273
struct Model: SmartCodable {
274274
var name: String = ""
275275

@@ -285,7 +285,7 @@ struct Model: SmartCodable {
285285

286286
Defines key mapping transformations during decoding,First non-null mapping is preferred。
287287

288-
```
288+
```swift
289289
static func mappingForKey() -> [SmartKeyTransformer]? {
290290
return [
291291
CodingKeys.id <--- ["user_id", "userId", "id"],
@@ -310,7 +310,7 @@ Convert between JSON values and custom types
310310
| **SmartDateFormatTransformer** | String | Date | Uses DateFormatter for custom date string formats |
311311
| **SmartURLTransformer** | String | URL | Converts strings to URLs with optional encoding and prefixing |
312312

313-
```
313+
```swift
314314
struct Model: SmartCodable {
315315

316316
...
@@ -329,7 +329,7 @@ struct Model: SmartCodable {
329329

330330
If you need additional parsing rules, **Transformer** will implement them yourself. Follow **ValueTransformable** to implement the requirements of the protocol.
331331

332-
```
332+
```swift
333333
public protocol ValueTransformable {
334334
associatedtype Object
335335
associatedtype JSON
@@ -344,7 +344,7 @@ public protocol ValueTransformable {
344344

345345
**Built-in Fast Transformer Helper**
346346

347-
```
347+
```swift
348348
static func mappingForValue() -> [SmartValueTransformer]? {
349349
[
350350
CodingKeys.name <--- FastTransformer<String, String>(fromJSON: { json in
@@ -372,7 +372,7 @@ static func mappingForValue() -> [SmartValueTransformer]? {
372372

373373
Codable does not support Any resolution, but can be implemented using @SmartAny
374374

375-
```
375+
```swift
376376
struct Model: SmartCodable {
377377
@SmartAny var dict: [String: Any] = [:]
378378
@SmartAny var arr: [Any] = []
@@ -395,7 +395,7 @@ print(model)
395395

396396
If you need to ignore the parsing of attributes, you can override `CodingKeys` or use `@IgnoredKey`.
397397

398-
```
398+
```swift
399399
struct Model: SmartCodable {
400400
@IgnoredKey
401401
var name: String = ""
@@ -414,7 +414,7 @@ print(model)
414414

415415
#### 3.3 @SmartFlat
416416

417-
```
417+
```swift
418418
struct Model: SmartCodable {
419419
var name: String = ""
420420
var age: Int = 0
@@ -442,7 +442,7 @@ print(model)
442442

443443
#### 3.4 @SmartPublished
444444

445-
```
445+
```swift
446446
class PublishedModel: ObservableObject, SmartCodable {
447447
required init() {}
448448

@@ -467,7 +467,7 @@ if let model = PublishedModel.deserialize(from: dict) {
467467

468468
Adds Codable support for UIColor/NSColor using hex string encoding/decoding.
469469

470-
```
470+
```swift
471471
struct Model: SmartCodable {
472472
@SmartHexColor
473473
var color: UIColor?
@@ -494,7 +494,7 @@ If you need inheritance support, annotate your subclass with `@SmartSubclass`.
494494

495495
#### 4.1 Basic Usage
496496

497-
```
497+
```swift
498498
class BaseModel: SmartCodable {
499499
var name: String = ""
500500
required init() { }
@@ -510,7 +510,7 @@ class StudentModel: BaseModel {
510510

511511
Just implement it directly—no need for the `override` keyword.
512512

513-
```
513+
```swift
514514
class BaseModel: SmartCodable {
515515
var name: String = ""
516516
required init() { }
@@ -532,7 +532,7 @@ class StudentModel: BaseModel {
532532

533533
#### 4.3 Parent Class Implements Protocol Method
534534

535-
```
535+
```swift
536536
class BaseModel: SmartCodable {
537537
var name: String = ""
538538
required init() { }
@@ -555,7 +555,7 @@ A few things to note:
555555
- The protocol method in the parent class must be marked with `class`.
556556
- The subclass should call the parent class's implementation.
557557

558-
```
558+
```swift
559559
class BaseModel: SmartCodable {
560560
var name: String = ""
561561
required init() { }
@@ -593,7 +593,7 @@ SmartCodable automatically handles string-encoded JSON values during decoding, s
593593
- **Recursive Mapping**: Applies `mappingForKey()` rules to parsed nested structures
594594
- **Type Inference**: Determines parsing strategy (object/array) based on property type
595595

596-
```
596+
```swift
597597
struct Model: SmartCodable {
598598
var hobby: Hobby?
599599
var hobbys: [Hobby]?
@@ -617,7 +617,7 @@ guard let model = Model.deserialize(from: dict) else { return }
617617

618618
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.
619619

620-
```
620+
```swift
621621
let dict = [
622622
"number1": "123",
623623
"number2": "Mccc",
@@ -656,7 +656,7 @@ This can greatly improve the analytical efficiency.
656656

657657
To be convertable, An `enum` must conform to `SmartCaseDefaultable` protocol. Nothing special need to do now.
658658

659-
```
659+
```swift
660660
struct Student: SmartCodable {
661661
var name: String = ""
662662
var sex: Sex = .man
@@ -675,7 +675,7 @@ let model = Student.deserialize(from: json)
675675

676676
Make the enumeration follow **SmartAssociatedEnumerable**。Override the **mappingForValue** method and take over the decoding process yourself.
677677

678-
```
678+
```swift
679679
struct Model: SmartCodable {
680680
var sex: Sex = .man
681681
static func mappingForValue() -> [SmartValueTransformer]? {
@@ -710,7 +710,7 @@ struct RelationEnumTranformer: ValueTransformable {
710710

711711
It can accommodate any data structure, including nested array structures.
712712

713-
```
713+
```swift
714714
struct Model: SmartCodable {
715715
var name: String = ""
716716
var age: Int = 0
@@ -773,7 +773,7 @@ Array<SomeModel> 👈🏻 👀
773773

774774
If you want to use it, turn it on:
775775

776-
```
776+
```swift
777777
SmartSentinel.debugMode = .verbose
778778
public enum Level: Int {
779779
case none
@@ -784,7 +784,7 @@ public enum Level: Int {
784784

785785
If you want to get this log to upload to the server:
786786

787-
```
787+
```swift
788788
SmartSentinel.onLogGenerated { logs in }
789789
```
790790

0 commit comments

Comments
 (0)