Hi, I'm trying to work with WidgetKit and get my widget to update once every hour and I'm having trouble figuring out how to do this. Mainly because I don't quite understand the concept of adding entries into a timeline. If I'm updating once an hour, cannot I not just add one entry that expires after an hour?
Anyway, I've got my widget setup but I'm trying to get the timeline part working. This is the code I have in my widget app, which was mostly populated by the default widget boilerplate you get when you create it.
How can I make my widget update once, every hour?
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [ScoreEntry] = []
let currentDate = Date()
for hourOffset in 0 ..< 6 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = ScoreEntry(date: entryDate, score: playerScore)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}