Finding an item

The quickest way to get a specific item from the database is to find it by ID. We can find an item by passing the ID into the static find method on our item class. Try this out by adding the following to the end of the main.swift file and running it. This code will print Apple in the console:

try print(Item.find(item.id)!.name)

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.