Contents

EntityQuery

An interface for locating entities using their identifiers.

Declaration

protocol EntityQuery : DynamicOptionsProvider, PersistentlyIdentifiable, Sendable

Mentioned in

Overview

The entity query provides the model object in which ways instances of a particular app entity type can be queried by Siri and the Shortcuts app, and implements the retrieval of such instances.

Conform to the EntityQuery Protocol

In order to allow Siri and Shortcuts to retrieve AppEntity instances, create a new type conforming to EntityQuery.

Resolving Entities by identifier

In some scenarios, Siri or Shortcuts already knows exactly which entity the user is referring to, and needs to retrieve the actual entity instance given its unique identifier.

To support this retrieval method, implement entities(for:), which given an array of AppEntity identifiers, returns corresponding entity instances. The method should first lookup if said instance already exists in memory. If the instance doesn’t exist, then perform can make asynchronous calls to retrieve the entity (ex: from disk or from a remote back-end). If the entity corresponding to a supplied identifier is not available anymore, then it should be omitted from the returned array.

struct MyPhotoQuery: EntityQuery {
    func entities(for identifiers: [UUID]) async throws -> [MyPhoto] {
        myPhotoStore.filter { identifiers.contains($0.id) }
    }
}

Topics

Creating a query

Searching for entities

Suggesting entities

Associated Types

See Also

Identifier-based queries