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
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,6 @@ Supercharge `Swift`'s `Codable` implementations with macros.
21
21
- Allows to create flattened model for nested `CodingKey` values with ``CodedAt(_:)`` and ``CodedIn(_:)``.
22
22
- Allows to create composition of multiple `Codable` types with ``CodedAt(_:)`` passing no arguments.
23
23
- Allows to provide default value in case of decoding failures with ``Default(_:)``.
24
-
- Generates member-wise initializer(s) considering the above default value syntax as well.
25
24
- Allows to create custom decoding/encoding strategies with ``HelperCoder`` and using them with ``CodedBy(_:)``. i.e. ``LossySequenceCoder`` etc.
26
25
- Allows to ignore specific properties from decoding/encoding with ``IgnoreCoding()``, ``IgnoreDecoding()`` and ``@IgnoreEncoding()``.
27
26
- Allows to use camel-case names for variables according to [Swift API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/#general-conventions), while enabling a type to work with different case style keys with ``CodingKeys(_:)``.
@@ -185,9 +184,9 @@ struct Coordinate {
185
184
</details>
186
185
187
186
<details>
188
-
<summary>Provide default value in case of decoding failures and member-wise initializer(s) generated considers these default values.</summary>
187
+
<summary>Provide default value in case of decoding failures.</summary>
189
188
190
-
Instead of throwing error in case of missing data or type mismatch, you can provide a default value that will be assigned in this case. The memberwise initializer generated also uses this default value for the field. The following definition with `MetaCodable`:
189
+
Instead of throwing error in case of missing data or type mismatch, you can provide a default value that will be assigned in this case. The following definition with `MetaCodable`:
191
190
192
191
```swift
193
192
@Codable
@@ -197,7 +196,20 @@ struct CodableData {
197
196
}
198
197
```
199
198
200
-
will not throw any error when empty JSON(`{}`) or JSON with type mismatch(`{ "field": 5 }`) is provided. The default value will be assigned in such case. Also, the memberwise initializer generated will look like this:
199
+
will not throw any error when empty JSON(`{}`) or JSON with type mismatch(`{ "field": 5 }`) is provided. The default value will be assigned in such case.
200
+
201
+
Also, memberwise initializer can be generated that uses this default value for the field.
202
+
203
+
```swift
204
+
@Codable
205
+
@MemberInit
206
+
structCodableData {
207
+
@Default("some")
208
+
let field: String
209
+
}
210
+
```
211
+
212
+
The memberwise initializer generated will look like this:
0 commit comments