Loading...
Loading...
Implement, review, or improve App Intents for Siri, Shortcuts, Spotlight, widgets, and Apple Intelligence. Use when creating AppIntent actions, defining AppEntity models with EntityQuery, building AppShortcutsProvider phrases, adding Spotlight indexing with IndexedEntity, integrating assistant schemas for Apple Intelligence, migrating from SiriKit to App Intents, building interactive widgets with WidgetConfigurationIntent, creating Control Center widgets, implementing SnippetIntent for visual intelligence, or wiring focus filters with SetFocusFilterIntent.
npx skill4agent add dpearson2699/swift-ios-skills app-intents| Surface | Protocol | Since |
|---|---|---|
| Siri / Shortcuts | | iOS 16 |
| Configurable widget | | iOS 17 |
| Control Center | | iOS 18 |
| Spotlight search | | iOS 18 |
| Apple Intelligence | | iOS 18 |
| Interactive snippets | | iOS 26 |
| Visual Intelligence | | iOS 26 |
AppEntityAppEnumEntityQueryIndexedEntity@Property(indexingKey:)AppIntent@Parameterperform() async throws -> some IntentResultparameterSummaryAppShortcutsProviderIndexedEntityWidgetConfigurationIntentinit()perform()titleparameterSummarystruct OrderSoupIntent: AppIntent {
static var title: LocalizedStringResource = "Order Soup"
static var description = IntentDescription("Place a soup order.")
@Parameter(title: "Soup") var soup: SoupEntity
@Parameter(title: "Quantity", default: 1) var quantity: Int
static var parameterSummary: some ParameterSummary {
Summary("Order \(\.$soup)") { \.$quantity }
}
func perform() async throws -> some IntentResult {
try await OrderService.shared.place(soup: soup.id, quantity: quantity)
return .result(dialog: "Ordered \(quantity) \(soup.name).")
}
}descriptionIntentDescriptionopenAppWhenRunBoolisDiscoverableBoolauthenticationPolicyIntentAuthenticationPolicy@Parameterdefault// WRONG: Non-optional parameter without default -- system cannot preview
@Parameter(title: "Count")
var count: Int
// CORRECT: Provide a default or make optional
@Parameter(title: "Count", default: 1)
var count: Int
@Parameter(title: "Count")
var count: Int?IntDoubleBoolStringURLDateDateComponentsCurrencyPersonIntentFileMeasurement<UnitLength>Measurement<UnitTemperature>AppEntityAppEnum// Basic
@Parameter(title: "Name")
var name: String
// With default
@Parameter(title: "Count", default: 5)
var count: Int
// Numeric slider
@Parameter(title: "Volume", controlStyle: .slider, inclusiveRange: (0, 100))
var volume: Int
// Options provider (dynamic list)
@Parameter(title: "Category", optionsProvider: CategoryOptionsProvider())
var category: Category
// File with content types
@Parameter(title: "Document", supportedContentTypes: [.pdf, .plainText])
var document: IntentFile
// Measurement with unit
@Parameter(title: "Distance", defaultUnit: .miles, supportsNegativeNumbers: false)
var distance: Measurement<UnitLength>references/appintents-advanced.mdstruct SoupEntity: AppEntity {
static let defaultQuery = SoupEntityQuery()
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Soup"
var id: String
@Property(title: "Name") var name: String
@Property(title: "Price") var price: Double
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "\(name)", subtitle: "$\(String(format: "%.2f", price))")
}
init(from soup: Soup) {
self.id = soup.id; self.name = soup.name; self.price = soup.price
}
}iddefaultQuerydisplayRepresentationtypeDisplayRepresentation@Property(title:)@Propertystruct SoupEntityQuery: EntityQuery {
func entities(for identifiers: [String]) async throws -> [SoupEntity] {
SoupStore.shared.soups.filter { identifiers.contains($0.id) }.map { SoupEntity(from: $0) }
}
func suggestedEntities() async throws -> [SoupEntity] {
SoupStore.shared.featured.map { SoupEntity(from: $0) }
}
}struct SoupStringQuery: EntityStringQuery {
func entities(matching string: String) async throws -> [SoupEntity] {
SoupStore.shared.search(string).map { SoupEntity(from: $0) }
}
func entities(for identifiers: [String]) async throws -> [SoupEntity] {
SoupStore.shared.soups.filter { identifiers.contains($0.id) }.map { SoupEntity(from: $0) }
}
}struct AllSoupsQuery: EnumerableEntityQuery {
func allEntities() async throws -> [SoupEntity] {
SoupStore.shared.allSoups.map { SoupEntity(from: $0) }
}
func entities(for identifiers: [String]) async throws -> [SoupEntity] {
SoupStore.shared.soups.filter { identifiers.contains($0.id) }.map { SoupEntity(from: $0) }
}
}struct AppSettingsEntity: UniqueAppEntity {
static let defaultQuery = AppSettingsQuery()
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Settings"
var displayRepresentation: DisplayRepresentation { "App Settings" }
var id: String { "app-settings" }
}
struct AppSettingsQuery: UniqueAppEntityQuery {
func entity() async throws -> AppSettingsEntity {
AppSettingsEntity()
}
}references/appintents-advanced.mdEntityPropertyQueryLosslessStringConvertibleStringenum SoupSize: String, AppEnum {
case small, medium, large
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Size"
static var caseDisplayRepresentations: [SoupSize: DisplayRepresentation] = [
.small: "Small",
.medium: "Medium",
.large: "Large"
]
}// WRONG: Using Int raw value
enum Priority: Int, AppEnum { // Compiler error -- Int is not LosslessStringConvertible
case low = 1, medium = 2, high = 3
}
// CORRECT: Use String raw value
enum Priority: String, AppEnum {
case low, medium, high
// ...
}struct MyAppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: OrderSoupIntent(),
phrases: [
"Order \(\.$soup) in \(.applicationName)",
"Get soup from \(.applicationName)"
],
shortTitle: "Order Soup",
systemImageName: "cup.and.saucer"
)
}
static var shortcutTileColor: ShortcutTileColor = .navy
}\(.applicationName)\(\.$soup)updateAppShortcutParameters()negativePhraseslet intent = OrderSoupIntent()
intent.soup = favoriteSoupEntity
try await intent.donate()PredictableIntentAppIntentButtonToggleWidgetConfigurationIntentstruct ToggleFavoriteIntent: AppIntent {
static var title: LocalizedStringResource = "Toggle Favorite"
@Parameter(title: "Item ID") var itemID: String
func perform() async throws -> some IntentResult {
FavoriteStore.shared.toggle(itemID)
return .result()
}
}
// In widget view:
Button(intent: ToggleFavoriteIntent(itemID: entry.id)) {
Image(systemName: entry.isFavorite ? "heart.fill" : "heart")
}struct BookWidgetConfig: WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Favorite Book"
@Parameter(title: "Book", default: "The Swift Programming Language") var bookTitle: String
}
// Connect to WidgetKit:
struct MyWidget: Widget {
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: "FavoriteBook", intent: BookWidgetConfig.self, provider: MyTimelineProvider()) { entry in
BookWidgetView(entry: entry)
}
}
}ControlConfigurationIntentControlWidgetstruct LightControlConfig: ControlConfigurationIntent {
static var title: LocalizedStringResource = "Light Control"
@Parameter(title: "Light", default: .livingRoom) var light: LightEntity
}
struct ToggleLightIntent: AppIntent {
static var title: LocalizedStringResource = "Toggle Light"
@Parameter(title: "Light") var light: LightEntity
func perform() async throws -> some IntentResult {
try await LightService.shared.toggle(light.id)
return .result()
}
}
struct LightControl: ControlWidget {
var body: some ControlWidgetConfiguration {
AppIntentControlConfiguration(kind: "LightControl", intent: LightControlConfig.self) { config in
ControlWidgetToggle(config.light.name, isOn: config.light.isOn, action: ToggleLightIntent(light: config.light))
}
}
}IndexedEntityindexingKeystruct RecipeEntity: IndexedEntity {
static let defaultQuery = RecipeQuery()
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Recipe"
var id: String
@Property(title: "Name", indexingKey: .title) var name: String // iOS 26+
@ComputedProperty(indexingKey: .description) // iOS 26+
var summary: String { "\(name) -- a delicious recipe" }
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "\(name)")
}
}struct OrderStatusSnippet: SnippetIntent {
static var title: LocalizedStringResource = "Order Status"
func perform() async throws -> some IntentResult & ShowsSnippetView {
let status = await OrderTracker.currentStatus()
return .result(view: OrderStatusSnippetView(status: status))
}
static func reload() { /* notify system to refresh */ }
}
// A calling intent can display this snippet via:
// return .result(snippetIntent: OrderStatusSnippet())struct ProductValueQuery: IntentValueQuery {
typealias Input = String
typealias Result = ProductEntity
func values(for input: String) async throws -> [ProductEntity] {
ProductStore.shared.search(input).map { ProductEntity(from: $0) }
}
}\(.applicationName)AppShortcutdefault// WRONG
@Parameter(title: "Count")
var count: Int
// CORRECT
@Parameter(title: "Count", default: 1)
var count: IntAppEnumRawRepresentableRawValue: LosslessStringConvertibleStringsuggestedEntities()EntityQueryentities(for:)updateAppShortcutParameters()IndexedEntitytypeDisplayRepresentationtypeDisplayRepresentation@AssistantIntent(schema:)@AppIntent(schema:)@AssistantIntentperform()awaitAppIntenttitle@ParameterAppEntityAppEntitydisplayRepresentationtypeDisplayRepresentationEntityQuery.entities(for:)suggestedEntities()AppEnumStringcaseDisplayRepresentationsAppShortcutsProvider\(.applicationName)parameterSummaryIndexedEntity@Property(indexingKey:)ControlConfigurationIntentWidgetConfigurationIntent@AssistantIntent@AssistantEntityperform()perform()Sendablereferences/appintents-advanced.md