Creating a BaseResourceController

If you look at the code for our ShoppingListController and our ItemController, you will see a lot of similarities between the two. The only difference is the type of class that is expected in the request. For example, in the show method of ItemController, it is expecting Item to be passed as a second argument and in ShoppingListController it is expecting an object of ShoppingList type. Using generics in Swift, we can create a BaseResourceController so that we can share the code between the two controllers. The following are the steps to do this refactoring:

  1. Create an empty new file called BaseResourceController.swift inside the Controllers folder.

 

  1. In there, import FluentProvider, as we will be referencing ...

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.