Skip to content

Instantly share code, notes, and snippets.

@giovani-pereira-ifood
Last active July 27, 2020 17:19
Show Gist options
  • Save giovani-pereira-ifood/6972c0737324821b64ee0e9996e03987 to your computer and use it in GitHub Desktop.
Save giovani-pereira-ifood/6972c0737324821b64ee0e9996e03987 to your computer and use it in GitHub Desktop.
struct User: Codable {
let name: String
let color: Color?
enum Color: String, Codable {
case red = "RED"
case yelllow = "YELLOW"
case blue = "BLUE"
}
}
// {
// "name": "Kermaine",
// "color": "GREEN"
// }
let data = requestData()
let decoder = JSONDecoder()
let object = try? decoder.decode(User.self, from: data)
print(object) // nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment