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
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,21 @@ struct User {
69
69
}
70
70
```
71
71
72
+
You can also derive default coding keys from property names:
73
+
74
+
```swift
75
+
@Codable(caseStyle: .snakeCase)
76
+
structExamplePayload {
77
+
let primaryValue: String
78
+
let secondaryLabel: String?
79
+
80
+
@CodingKey("ManualName")
81
+
let customField: String?
82
+
}
83
+
```
84
+
85
+
This generates coding keys like `"primary_value"` and `"secondary_label"`, while `customField` still uses `"ManualName"`.
86
+
72
87
Let's convert `birthday` to `Date`, change coding key of `isVerified` and make it default to `false`
73
88
74
89
> **Note**
@@ -284,6 +299,8 @@ struct User {
284
299
}
285
300
```
286
301
302
+
When `@Codable(caseStyle: ...)`, `@Decodable(caseStyle: ...)`, or `@Encodable(caseStyle: ...)` is used, `@CodingKey(...)` still takes precedence for that property.
303
+
287
304
#### @OmitCoding
288
305
289
306
Skip coding for a specific property with `@OmitCoding()` annotation
0 commit comments