Created
August 10, 2021 17:05
-
-
Save oconnelltoby/8b3b6eec369ce9104a707e15e87b6c62 to your computer and use it in GitHub Desktop.
A wrapper for potentially malformed JSON objects
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
struct OptionallyDecodable<Value: Decodable>: Decodable { | |
let value: Value? | |
init(from decoder: Decoder) throws { | |
do { | |
let container = try decoder.singleValueContainer() | |
self.value = try container.decode(Value.self) | |
} catch { | |
self.value = nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment