Deleting a Shopping List
To delete a Shopping List is similar to adding. We need to define a new delete
method on the Shopping List class. In that method, make a DELETE
request to the /shopping_lists/:id endpoint
where :id
is the ID of our Shopping List model. We already have to delete implemented in our Table View Controller but we need to invoke this new delete
method from our Table View Controller, and, on a successful DELETE
request to our API server, we need to update the Table View by reloading it. To add the delete functionality, we need to follow these steps:
- Open the
ShoppingList.swift
file from our iOS project and add the followingdelete
method to the class. In this method, we make the request by specifying theDELETE
HTTP method and also pass theid
of the Shopping List we want to delete in the URL. On completion, we call theonCompletion
closure function passed as part of thedelete
method invocation:
func delete(onCompletion: @escaping () -> Void) { request(url: "/shopping_lists...