0

I want to add more advanced configuration options to my iOS 14 Widgets. This is what I've been working with:

struct WidgetConfig {
    let id: UUID
    let name: String
    let backgroundColor: Color?
    let backgroundImage: Data?
    let fontColor: Color
    let fontStyle: Font.Design
    let accentColor: Color
}

The user can create Configurations in the App.

I experimented with storing the Configurations in CoreData, but fetching them in the IntentHandler is very slow and unreliable. Widgets often just render black.

What would be a better strategy to implement this?

1
  • What about using a JSON encoder and saving them in a JSON file or User Defaults?
    – Chris
    Commented Jan 7, 2021 at 12:03

1 Answer 1

0

The official way to customize Widgets is using a Siri intent file. This enables the options you see when long pressing a widget and choosing edit (the widget flips around).

To make the most relevant information easily accessible to users, widgets can provide customizable properties. For example, users can select a specific stock for a stock quote widget, or enter a tracking number for a package delivery widget. Widgets define customizable properties by using custom intent definitions, the same mechanism that Siri Suggestions and Siri Shortcuts use for customizing those interactions. To add configurable properties to your widget:

  1. Add a custom intent definition that defines the configurable properties to your Xcode project.
  2. Use an IntentTimelineProvider in your widget to incorporate the user’s choices into your timeline entries.
  3. If the properties rely on dynamic data, implement an Intents extension.

– From Apple’s Article: Making a Configurable Widget

There is also a detailed WWDC session on that topic I can recommend: https://developer.apple.com/wwdc20/10194

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.