Finding items using filter

Fluent makes it easy to find multiple items using the filter method, which is similar to performing a WHERE clause in SQL. To see how this works, add the following line to the bottom of the main.swift file and it will print the names of all items that are unchecked:

let uncheckedItems = try Item.makeQuery().filter("isChecked", .equals, false).all()uncheckedItems.forEach { print($0.name) }

You can also chain the filter methods so that you can filter based on two or more columns:

let uncheckedItems = try Item.makeQuery().filter("isChecked", .equals, false).filter("name", .equals, "Apple").all()uncheckedItems.forEach { print($0.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.