From the course: iOS App Development: RESTful Web Services

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Manual decoding of data

Manual decoding of data - iOS Tutorial

From the course: iOS App Development: RESTful Web Services

Start my 1-month free trial

Manual decoding of data

- [Instructor] If you've ever worked with a server API in the past, you know that many times the data doesn't line up 100 percent the same. Sometimes it's the date format that needs to be changed, or somehow otherwise, it just doesn't map one to one in your conversion from the data on the server into your instances of classes in your app. In this case, we can manually decode data from the server into our instance. All we have to do is implement the Decodable protocol method for the init. We saw that in the documentation, but it takes a decoder that's passed in, and we simply use that to access the values to be able to set into our properties. When the dot decode is called, the decoder is actually passed in. And through that we can access the container and decode the values using the CodingKeys that we established in our class already. So what we do is we manually implement the init method on the decodable protocol. So we create an init function that takes the decoder so I'll give it…

Contents