Codable provides a way to convert to and from formats such as JSON. In this tutorial we’ll just focus on converting JSON. The JSON format is popular among web services and provides a standard about how data can be represented. JSON formatted data can be understood by various systems making it possible to easily transfer data from one system to another regardless of operating system or programming language used.
On the iOS side, Codable is one way to convert an object or structure in to the JSON format so that the other end of the network can accept it and understand it as needed.
The Gmail API is one example of a service that provides data in JSON form. When you query the API the results come back as JSON. We don’t particularly care what programming language and operating systems are involved on the other side. All we need to know is that the response provided conforms to the JSON standard and thus, we can use Codable to convert that data in to whatever we need within our code.[Read more…]