Adding a Shopping List Item
If you have successfully implemented the create and delete functionality for an item in the Shopping List, then good job! If not, we will walk through how you can do so. It is very similar to how we implemented it on the Shopping List. To implement the functionality for adding items to a Shopping List, we need to follow these steps:
- Open the
Item.swift
file inside the iOS project and add a new instance variable to store theshoppingListId
. This variable will be passed to the API server along with thename
and theisChecked
state of the item when creating it so that it can associate this item with the shopping list it is being added to:
var shoppingListId: String?
- Add the data commuted property, similar to the one we added in the
ShoppingList
class, which will convert our object into JSON data that will be passed to our API server. In this case, we will useJSONEncoder
instead ofJSONSerializer
. The reason why we did not convertShoppingList
to JSON data using this...