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
+65
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,32 @@ struct Book {
92
92
93
93
This will cause `synopsis` to not be safely decoded in the initializer.
94
94
95
+
The `@FallbackDecoding` macro can be used to grant fallback semantics to properties.
96
+
`@FallbackDecoding` must be used with `@SafeDecoding`, and means decoding will never fail properties it is applied to (even if the type is not otherwise "safe-decodable"):
97
+
98
+
```swift
99
+
@SafeDecoding
100
+
structBook {
101
+
@FallbackDecoding(false)
102
+
var isFavourite: Bool
103
+
}
104
+
```
105
+
106
+
The `RetryDecoding` macro can in turn be used to provide alternative decoding of a property; an alternative decoding type and a "mapper" between types must be provided.
107
+
An example could be a backend that sometimes returns integers as strings, or booleans as integers:
Finally, `@SafeDecoding` can report errors that occur (and are recovered from) during the decoding process.
134
+
This is done by passing the `reporter:` parameter to the macro:
135
+
136
+
```swift
137
+
@SafeDecoding(reporter:...)
138
+
structBook {
139
+
....
140
+
}
141
+
```
142
+
143
+
The reporter must conform the `SafeDecodingReporter` protocol.
144
+
Upon recovery of decoding errors, the reporter will be called with information about said error.
145
+
Remember that a reporter is local to its type, i.e. although the same type may be used everywhere **each @SafeDecoding usage must be given its reporter expression**.
146
+
147
+
# Versions
148
+
149
+
## Version 1.3.0
150
+
151
+
- Add `@RetryDecoding`, allowing individual properties to have associated retries
152
+
- Add `@FallbackDecoding`, allowing individual properties to provide a last-resort value
153
+
154
+
## Version 1.2.1
155
+
156
+
- Bug: uses `decodeIfPresent` for optionals when using error reporting
157
+
158
+
## Version 1.2.0
159
+
160
+
- Accounts for access modifiers
161
+
162
+
## Version 1.1.0
163
+
164
+
- Add error reporting to `@SafeDecoding` macro
165
+
- Remove sample client product
166
+
167
+
## Version 1.0.0
168
+
169
+
- Add `@SafeDecoding` and `@IgnoreSafeDecoding` macros
0 commit comments