Created
July 3, 2024 11:15
-
-
Save velotiotech/82991553d72d2bcc7a819bbd7595e27e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Provider: TimelineProvider { | |
// Provides a placeholder entry while the widget is loading. | |
func placeholder(in context: Context) -> DayEntry { | |
DayEntry(date: Date(), configuration: ConfigurationIntent()) | |
} | |
// Provides a snapshot of the widget's current state. | |
func getSnapshot(in context: Context, completion: @escaping (DayEntry) -> ()) { | |
let entry = DayEntry(date: Date(), configuration: ConfigurationIntent()) | |
completion(entry) | |
} | |
// Provides a timeline of entries for the widget. | |
func getTimeline(in context: Context, completion: @escaping (Timeline<DayEntry>) -> ()) { | |
var entries: [DayEntry] = [] | |
let currentDate = Date() | |
// Generate seven entries, each one day apart, starting from the current date. | |
for dayOffset in 0 ..< 7 { | |
let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate)! | |
let startOfDate = Calendar.current.startOfDay(for: entryDate) | |
let entry = DayEntry(date: startOfDate, configuration: ConfigurationIntent()) | |
entries.append(entry) | |
} | |
let timeline = Timeline(entries: entries, policy: .atEnd) | |
completion(timeline) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment