Keeping our widgets up to date
We have learned that we need to look ahead and create a timeline with different entries and dates to keep our widget up to date. But how does our widget work under the hood?
Widgets don’t get any running time – once we generate the timeline entries, WidgetCenter generates their different views, keeps them persistently, and just switches them according to the provided timeline.
So, there’s no way to update our widget without reloading the timeline, and when we created our timeline, we had to define its reload policy:
let timeline = Timeline(entries: entries, policy: .atEnd)
However, sometimes, we want to instruct WidgetCenter
to reload the timeline immediately, due to data changes or any other alterations.
Let’s see how it happens.
Reload widgets using the WidgetCenter
Throughout the chapter, I have mentioned WidgetCenter frequently but I haven’t explained what it means.
WidgetCenter is an object...