Member-only story
Implementing SwiftUI TimelineView in iOS 15
Let’s build a digital clock using the new Canvas View

Have you heard of crontab? No, he isn’t a DC hero. It has been around since 1975, an eternity. iOS used to run a crontab, although looking through SO posts, it has long since disappeared. Of course, it is still around on OS X, type “crontab -l” under the shell and you’ll get a response.
But maybe all is not lost, since with iOS 15 Apple has launched a new view dedicated to running jobs on a schedule, a bit like crontab. I say run a job, I mean refreshing a view on a schedule. Now; I should confess at this point that I wasn’t quite sure how I would be supposed to use this new view. I wasn’t sure because we already had a scheduler in SwiftUI. A scheduler that looks like this.
let timer = Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()
A scheduler you could catch in your code and force a view refresh of sorts. A refresh of every 0.5 seconds in the case shown.
.onReceive(timer) { _ in
refresh += 1
}.id(refresh)
I can only assume they decided to create a view dedicated view to scheduling because it fits with the single source of truth philosophy in SwiftUI. A single source for scheduling all the code your app should be referencing. Join me on…