Contents

EntityQuery

An interface for locating app entity instances by identifier.

Declaration

protocol EntityQuery : DynamicOptionsProvider, PersistentlyIdentifiable, Sendable

Mentioned in

Overview

An entity query defines how Apple Intelligence, Siri, and the Shortcuts app retrieve instances of a specific AppEntity type, and implements the lookup logic. To let Siri and Shortcuts retrieve AppEntity instances, create a type that conforms to EntityQuery.

Resolve entities by identifier

In some scenarios, Apple Intelligence already knows exactly which entity the person 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. In your entities(for:) implementation, first look up whether the instance already exists in memory. If the instance doesn’t exist, make asynchronous calls — for example, retrieving from disk or a backend service. If the entity for a provided identifier is no longer available, omit it 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

Instance Methods

Type Aliases

Type Properties

See Also

Identifier-based queries