Widgets with WidgetKit: getting your app onto the Home Screen

Widgets bring your app to the Home Screen, Lock Screen and Apple Watch. How WidgetKit works and what makes a good widget.

2 min readby Luca Ring

For many users, a good widget is the reason they see an app every day without opening it. With WidgetKit you build widgets in SwiftUI for the Home Screen, the Lock Screen, Notification Center on the Mac, StandBy and even Apple Watch.

How widgets think

Widgets don't run all the time. Instead, you give the system a timeline: a list of entries with dates, and the system shows the right entry at the right time. That saves battery and is the key idea to understand.

struct Entry: TimelineEntry {
    let date: Date
    let thought: String
}

struct Provider: TimelineProvider {
    func placeholder(in context: Context) -> Entry {
        Entry(date: .now, thought: "Grateful today for …")
    }
    func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
        completion(placeholder(in: context))
    }
    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
        let tomorrow = Calendar.current.startOfDay(for: .now.addingTimeInterval(86_400))
        completion(Timeline(entries: [placeholder(in: context)], policy: .after(tomorrow)))
    }
}

Then comes the widget struct with StaticConfiguration or, if users should configure something, AppIntentConfiguration. The view is plain SwiftUI, but since iOS 17 it needs a background via containerBackground.

Interactive widgets

Since iOS 17, widgets can have buttons and toggles. They trigger an App Intent without opening the app. Perfect for small actions: check off a task, log a habit, bump a counter.

What makes a good widget

  • One job: a widget answers one question at a glance. Everything else belongs in the app.
  • Share data: app and widget are separate processes. Shared data lives in an App Group, for example via SwiftData or UserDefaults with a suite name.
  • Trigger reloads: when something changes in the app, call WidgetCenter.shared.reloadAllTimelines().
  • Test every appearance: tinted, clear, dark and StandBy. With iOS 26, widgets get the glass look too, see Liquid Glass in SwiftUI.

Bring it to the watch too

Lock Screen widgets (accessoryCircular, accessoryRectangular, accessoryInline) also work as complications on Apple Watch with small adjustments. How to build a watch app is covered in An Apple Watch app with SwiftUI.

  • WidgetKit
  • widgets
  • SwiftUI
  • App Intents
  • iOS