Contents

IntentConfiguration

An object describing the content of a widget that uses a custom intent definition to provide user-configurable options.

Declaration

@MainActor @preconcurrency struct IntentConfiguration<Intent, Content> where Intent : INIntent, Content : View

Overview

The following example shows the configuration for a game widget that displays details about a chosen character.

struct CharacterDetailWidget: Widget {
    var body: some WidgetConfiguration {
        IntentConfiguration(
            kind: "com.mygame.character-detail",
            intent: SelectCharacterIntent.self,
            provider: CharacterDetailProvider(),
        ) { entry in
            CharacterDetailView(entry: entry)
        }
        .configurationDisplayName("Character Details")
        .description("Displays a character's health and other details")
        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
    }
}

Every widget has a unique kind, a string that you choose. You use this string to identify your widget when reloading its timeline with WidgetCenter.

The intent is a custom SiriKit intent definition containing user-editable parameters.

The timeline provider is an object that determines the timeline for refreshing your widget. Providing future dates for updating your widget allows the system to optimize the refresh process.

The content closure contains the SwiftUI views that WidgetKit needs to render the widget. When WidgetKit invokes the content closure, it passes a timeline entry created by the widget provider’s getSnapshot(for:in:completion:) or getTimeline(for:in:completion:) method.

Modifiers let you specify the families your widget supports, and the details shown when users add or edit their widgets.

Topics

Creating a widget configuration

Setting the display name

Setting the description

Setting the supported families

Handling background network requests

See Also

Smart Stacks