Skip to content

Instantly share code, notes, and snippets.

@jakehawken
Created March 6, 2019 20:21
Show Gist options
  • Save jakehawken/8cc082316ee71de61ddf18384fa00205 to your computer and use it in GitHub Desktop.
Save jakehawken/8cc082316ee71de61ddf18384fa00205 to your computer and use it in GitHub Desktop.
SwiftyJSON + Codable
import SwiftyJSON
extension JSON {
func parseTo<T: Codable>() -> T? {
guard let data = try? rawData(options: .prettyPrinted) else {
return nil
}
let decoder = JSONDecoder()
return try? decoder.decode(T.self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment