Last active
May 20, 2022 14:21
-
-
Save antoniopantaleo/f42dd3c44fb7b2af170b4dae26c8a18f to your computer and use it in GitHub Desktop.
Decode a generic decodable object
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
public extension JSONDecoder { | |
static func decode<T:Decodable>(from data: Data) -> T? { | |
do { return try JSONDecoder().decode(T.self, from: data) as T } | |
catch { return nil } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage