Contents

AppIntent

An interface for providing an app-specific capability that people invoke from system experiences like Siri and the Shortcuts app.

Declaration

protocol AppIntent : PersistentlyIdentifiable, _SupportsAppDependencies, Sendable

Mentioned in

Overview

To expose your app’s functionality to system experiences like Siri or the Shortcuts app, and to support interactivity in widgets, you need to implement the AppIntent protocol. Use it to provide phrases that can launch the functionality, describe the needed data for the functionality you make available, and implement the method that performs the functionality.

The system instantiates an app intent you create parameter-less using the init() initializer whenever a person invokes it through a system service like Siri, Shortcuts, and so on. If available, the system sets parameters based on user input or other available sources. With set parameters, the system attempts to resolve them in the order of their declaration in the AppIntent body. After it resolves all parameters, the system calls perform() to perform the app intent with its configured parameters. Note that the system retains the app intent and its output only for the duration of the invocation.

Implement the AppIntent Protocol

Declare a custom intent type by defining a structure that conforms to the AppIntent protocol:

struct OrderSoupIntent: AppIntent {
   static var title = LocalizedStringResource("Order Soup")
   static var description = IntentDescription("Orders a soup from your favorite restaurant.")
}

Then, declare the AppIntent’s parameters. When you implement an AppIntent type, parameters must be declared with the @Parameter property wrapper. For more information about declaring parameters, see Adding parameters to an app intent.

struct OrderSoupIntent: AppIntent {
   @Parameter(title: "Soup")
   var soup: Soup

   @Parameter(title: "Quantity")
   var quantity: Int?
}

Next, implement the required perform()function: Validate your intent’s parameters, execute the intent, and return an IntentResult that represents the output of a completed intent; for example, a PerformResult.

struct OrderSoupIntent: AppIntent {
    @Parameter(title: "Soup")
    var soup: Soup

    @Parameter(title: "Quantity")
    var quantity: Int?

    static var parameterSummary: some ParameterSummary {
        Summary("Order \(\.$soup)") {
            \.$quantity
        }
    }

    func perform() async throws -> some IntentResult {
        guard let quantity = quantity, quantity < 10 else {
            throw $quantity.needsValue
        }
        soup.order(quantity: quantity)
        return .result()
    }
}

Topics

Creating an app intent

Specifying the authentication policy

Configuring the metadata

Performing the action

Requesting confirmation

Donating the intent to the system

Summarizing the parameters

URL representation

Instance Methods

Type Aliases

Type Properties

See Also

General actions