Created
February 18, 2021 03:53
-
-
Save ha1f/3f67a171d0ce47814343f399bcc67c7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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