JSONConvertible protocol

Now we have the ShoppingList Model ready, but we still need to extend it to support converting it to a JSON object and converting a JSON object into a ShoppingList Model, which is similar to converting it to a row for the database. This will help us return the instance of this class as a JSON representation, which is the universal format and is similar to XML in exchanging data across applications. We will also be using this JSON Response in our iOS app. To convert ShoppingList to JSON and vice versa, we need to extend the class with two methods. One will be an initializer that will take in a JSON object and create a new ShoppingList instance, and another will be a makeJSON method that will convert the ShoppingList ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.