Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public extension KeyedDecodingContainerProtocol {
func decode<T: Decodable>(forKey key: Key) throws -> T {
try decode(T.self, forKey: key)
}
func decodeSafe<T: Decodable>(forKey key: Key, defaultValue: T) -> T {
(try? decode(T.self, forKey: key)) ?? defaultValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment