Resilient Decoding in Swift
This package defines mechanisms to partially recover from errors when decoding
Decodable
types. It also aims to provide an ergonomic API for inspecting decoding errors during development and reporting them in production.[…]
After running this code,
foo
will be aFoo
wherefoo.array == [1, 3]
andfoo.value == nil
. In DEBUG,foo.$array.results
will be[.success(1), .failure(DecodingError.dataCorrupted(…), .success(3)]
andfoo.$value.error
will beDecodingError.dataCorrupted(…)
. This functionality isDEBUG
-only so that we can maintain no overhead in release builds.
Cool use of Swift property wrappers and projected values.
See also:
- Better Codable Through Property Wrappers
- How can Property Wrappers and Function Builders be leveraged?
- Implementing the Service Locator Pattern using a Property Wrapper in Swift 5.1
- Using and creating Property Wrappers
- Turning Property Wrappers into Function Wrappers
Previously:
- Facebook SDK Causes Crashes
- Making Swift Properties Overridable Only in Debug Builds
- Swift Property Wrappers