DynamicOptionsProvider
An interface for providing a dynamic list of options for a parameter of your app intent.
Declaration
protocol DynamicOptionsProvider : _SupportsAppDependenciesMentioned in
Overview
Implement this protocol in a type that provides a set of possible values for an intent parameter. When configuring the parameter, specify your custom type as the options provider for that parameter. The type of result you return determines how the system displays the information.
Return an array of DisplayRepresentable types to display a list of values.
Return an array of IntentItem types to divide values into sections or configure other presentation options.
The following example shows the configuration of a custom parameter that contains the author name of a book. The options provider offers two possible suggestions for the author name. For brevity, it omits the rest of the implementation.
struct CreateBook: AppIntent {
@Parameter(title: "Author Name",
optionsProvider: AuthorNamesOptionsProvider())
var authorName: String
// Other properties and the perform() implementation.
private struct AuthorNamesOptionsProvider: DynamicOptionsProvider {
func results() async throws -> [String] {
["Juan Chavez", "Anne Johnson"]
}
}
}