Skip to content

Instantly share code, notes, and snippets.

@helbertgs
Created April 18, 2019 17:00
Show Gist options
  • Save helbertgs/6f70fa1cd42db6e4702bd9f4501f1bca to your computer and use it in GitHub Desktop.
Save helbertgs/6f70fa1cd42db6e4702bd9f4501f1bca to your computer and use it in GitHub Desktop.
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