Deleting an Item is very similar to deleting a Shopping List where we need to make a DELETE
request to the /items
endpoint instead, with the ID of the item passed in the URL. Just like addition, we need to update the remove
method inside the ShoppingList
class so that it can make a network request to delete and invoke an onCompletion
handler that we can use to update the tableView
. For this, we need to make two changes. They are as follows:
- Inside of the
ShoppingList.swift
file of the iOS project, update the method signature of theremove
method to take an extra parameter called theonCompletion
closure function. Inside this function, make the network request to delete the item from the server. On success, remove the item from the Shopping List's items array and call theonCompletion
handler. The updatedremove
method looks like the following:
func remove(at index: Int, onCompletion: @escaping () -> Void) { let itemId = self.items[index].id! request(url: "/items/\(itemId...