Created
April 18, 2019 17:00
-
-
Save helbertgs/6f70fa1cd42db6e4702bd9f4501f1bca to your computer and use it in GitHub Desktop.
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
extension Decodable { | |
static func parse(json: String) -> Self? { | |
guard let url = Bundle.main.url(forResource: json, withExtension: "json"), | |
let data = try? Data(contentsOf: url), | |
let output = try? JSONDecoder().decode(self, from: data) else { | |
return nil | |
} | |
return output | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment