Contents

getSnapshot(for:in:completion:)

Provides a timeline entry representing the current time and state of a widget.

Declaration

@preconcurrency func getSnapshot(for configuration: Self.Intent, in context: Self.Context, completion: @escaping  @Sendable (Self.Entry) -> Void)

Parameters

  • configuration:

    The intent containing user-customized values.

  • context:

    An object describing the context to show the widget in.

  • completion:

    The completion handler to call after you create the snapshot entry.

Discussion

WidgetKit calls getSnapshot(for:in:completion:) when the widget appears in transient situations. If context.isPreview is true, the widget appears in the widget gallery. In that case, call the completion handler as quickly as possible, perhaps supplying sample data if it could take more than a few seconds to fetch or calculate the widget’s current state.

The configuration parameter provides user-customized values, as defined in your custom intent definition.

See Also

Generating Timelines