Codable in Swift and iOS

Photo by Ravi Roshan on Unsplash

Prerequisites:

Terminology

The implementation: codable

The implementation: codable snake_case

decoder.keyDecodingStrategy = .convertFromSnakeCase

The implementation: non-matching key names

let data = “””{“idforuser”: 1,“globalid”: 2,“usertitle”: “test”,“complete”: true}“””

The implementation: nested JSON

Parsing data using coding

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
let readableDateFormatter = DateFormatter()
readableDateFormatter.dateFormat = "M-dd-yyyy HH:mm"
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(formatter)

Conclusion:

Extend your knowledge

The Twitter contact:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store