Skip to content

Instantly share code, notes, and snippets.

@gavi
Created July 15, 2017 16:19
Show Gist options
  • Save gavi/eeedaa6b51fd094cd7150812683145cf to your computer and use it in GitHub Desktop.
Save gavi/eeedaa6b51fd094cd7150812683145cf to your computer and use it in GitHub Desktop.
JSON Decoding in Swift Basic
let inputData = """
{"x":10,"y":10,"moment":"2017-06-08T21:36:37Z"}
""".data(using: .utf8)!
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
let obj=try? decoder.decode(Point.self, from: inputData)
if let point=obj{
print(point.x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment