<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppIntentsTesting",
  "identifier" : "/documentation/AppIntentsTesting/AppEntityDefinition",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "App Intents Testing"
    ],
    "preciseIdentifier" : "s:17AppIntentsTesting0A16EntityDefinitionV"
  },
  "title" : "AppEntityDefinition"
}
-->

# AppEntityDefinition

A definition you use to dynamically create entity instances for testing.

```
struct AppEntityDefinition
```

## Overview

To create an app entity instance for testing, load the definition for your app entity, using
[`IntentDefinitions`](/documentation/AppIntentsTesting/IntentDefinitions) and its [`entities`](/documentation/AppIntentsTesting/IntentDefinitions/entities) property,
then create an entity instance as shown in the following example:

```swift
let definitions = IntentDefinitions(
    bundleIdentifier: "com.apple.example"
)
let landmarkEntity = definitions.entities[
    "LandmarkEntity"
]
let entity = landmarkEntity.makeReference(
    identifier: "yosemite-falls"
)
```

## Topics

### Creating an app entity instance

[`func makeReference(identifier: String) -> AnyAppEntity`](/documentation/AppIntentsTesting/AppEntityDefinition/makeReference(identifier:))

Creates an app entity instance of the given entity type.

### Retrieving all entities

[`func allEntities() async throws -> [AnyAppEntity]`](/documentation/AppIntentsTesting/AppEntityDefinition/allEntities())

Fetches all available entities of this type.

[`func allEntitiesQuery() -> AnyEntityQuery`](/documentation/AppIntentsTesting/AppEntityDefinition/allEntitiesQuery())

Creates an entity query that retrieves all available entities
of this type.

### Searching matching entities

[`func entities<Identifier>(identifiers: [Identifier]) async throws -> [AnyAppEntity]`](/documentation/AppIntentsTesting/AppEntityDefinition/entities(identifiers:))

Retrieves entities by their identifiers.

[`func entityQuery<Identifier>(identifiers: [Identifier]) -> AnyEntityQuery`](/documentation/AppIntentsTesting/AppEntityDefinition/entityQuery(identifiers:))

Creates an entity query that searches for entities by their
identifiers.

[`func entities(matching: String) async throws -> [AnyAppEntity]`](/documentation/AppIntentsTesting/AppEntityDefinition/entities(matching:))

Finds app entities that match a given string query.

[`func entityQuery(matching: String) -> AnyEntityQuery`](/documentation/AppIntentsTesting/AppEntityDefinition/entityQuery(matching:))

Creates an entity query that searches for entities that match
a given string.

[`func spotlightQuery(String?) async throws -> [AnyAppEntity]`](/documentation/AppIntentsTesting/AppEntityDefinition/spotlightQuery(_:))

Performs a Spotlight search query for entities of this type.

### Accessing suggested entities

[`func suggestedEntities() async throws -> [AnyAppEntity]`](/documentation/AppIntentsTesting/AppEntityDefinition/suggestedEntities())

Fetches all suggested entities of this type.

[`func suggestedEntitiesQuery() -> AnyEntityQuery`](/documentation/AppIntentsTesting/AppEntityDefinition/suggestedEntitiesQuery())

Creates an entity query that retrieves suggested entities of this type.

### Accessing onscreen entities

[`func viewAnnotations() async throws -> [ViewAnnotation]`](/documentation/AppIntentsTesting/AppEntityDefinition/viewAnnotations())

Provides the currently visible onscreen entities.

### Identifying the entity

[`let typeIdentifier: String`](/documentation/AppIntentsTesting/AppEntityDefinition/typeIdentifier)

The entity type’s unique identifier.

[`let bundleIdentifier: String`](/documentation/AppIntentsTesting/AppEntityDefinition/bundleIdentifier)

The bundle identifier of the app that includes the app entity.

### Instance Methods

[`func resolved(from: IntentFile) async throws -> AnyAppEntity`](/documentation/AppIntentsTesting/AppEntityDefinition/resolved(from:)-2fld0)

Resolves an entity from an exported intent file through the entity type’s
transferable conformance.

[`func resolved<T>(from: T) async throws -> AnyAppEntity`](/documentation/AppIntentsTesting/AppEntityDefinition/resolved(from:)-4yp5n)

Resolves an entity from a system intent value type through the entity type’s
transferable conformance.

[`func resolved<T>(from: T) async throws -> AnyAppEntity`](/documentation/AppIntentsTesting/AppEntityDefinition/resolved(from:)-7c04a)

Resolves an entity from a transferable intent value type through the entity type’s
transferable conformance.

### Default Implementations

[AppIntentTypeDefinition Implementations](/documentation/AppIntentsTesting/AppEntityDefinition/AppIntentTypeDefinition-Implementations)

## Relationships

### Conforms To

[`AppIntentTypeDefinition`](/documentation/AppIntentsTesting/AppIntentTypeDefinition)

[`Copyable`](/documentation/Swift/Copyable)

[`Equatable`](/documentation/Swift/Equatable)

[`Escapable`](/documentation/Swift/Escapable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)