0Pricing
Swift Academy · Lesson

Timeline Providers and Snapshots

Supply widget content over time.

The Provider's Job

A widget never updates itself continuously. Instead, a TimelineProvider hands WidgetKit a schedule of pre-rendered entries, and the system displays each at the right time. The provider answers three questions: placeholder, snapshot, and timeline.

import WidgetKit
// TimelineProvider supplies:
//   placeholder(in:) -> instant skeleton
//   getSnapshot(in:)  -> one entry for previews
//   getTimeline(in:)  -> future entries + refresh policy

Conforming to TimelineProvider

A provider conforms to TimelineProvider with an associated Entry type. You implement the three methods; each gives you a Context describing the family and whether it is a preview.

import WidgetKit
struct WeatherProvider: TimelineProvider {
    typealias Entry = WeatherEntry
    func placeholder(in context: Context) -> WeatherEntry {
        WeatherEntry(date: Date(),
            temperature: 20, condition: "Sunny")
    }
    // getSnapshot and getTimeline follow
}

All lessons in this course

  1. Building a WidgetKit Widget
  2. Timeline Providers and Snapshots
  3. App Extensions Overview
  4. App Intents and Shortcuts
← Back to Swift Academy