Last active
December 9, 2022 23:05
-
-
Save xr1337/7bccf3dac76e56f2fa2555a992f96685 to your computer and use it in GitHub Desktop.
A json wrapper that holds the decode status of json objects. Generally used to decode JSON container items that may fail such as JSON Arrays.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This is wrapper that holds the decode status of json objects | |
/// It is useful for JSON arrays where if one child JSON node fails to decode, the whole array is not nil | |
/// Example use: try JSONDecoder().decode([DecodableResult<MyProduct>]).compactMap { try? $0.result.get() } | |
struct DecodableResult<T: Decodable>: Decodable { | |
let result: Result<T, Error> | |
init(from decoder: Decoder) throws { | |
result = Result(catching: { try T(from: decoder) }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment