Updateable protocol

There is one more protocol that comes in handy when we want to update a Model in the database table, and that is the Updateable protocol. This protocol simply needs the Model class to define a static computed property that should return an array of UpdateableKeys. UpdateableKey is nothing but a wrapper class that needs the name of the property that can be updated and the type.

It will extract that value from the request object and pass it into the callback, where you can use it to update the property of your existing object. Implementing this is very easy and requires extending your Model class and adding the following computed property:

extension ShoppingList: Updateable { public static var updateableKeys: [UpdateableKey<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.