We’ve arrived at day 87 of the 100 Days of SwiftUI! Yesterday, we started the Flashzilla project with at gestures and vibrations. Today, we’re learning how to trigger events using a timer and how to be notified when our SwiftUI app moves to the background. Let’s dive in!
Triggering events repeatedly using a timer
iOS features a built in
Timer class. This class allows us to schedule and run code on a regular basis, which uses a system of publishers that comes from an Apple framework called Combine. We can use this functionality to repeatedly run some code at a specific time interval.
How to be notified when your SwiftUI app moves to the background
SwiftUI can detect when your app moves to the background (i.e., when the user returns to the home screen), and when it comes back to the foreground. By detecting this, SwiftUI knows then to pause the app and resume it again. This comes in handy in a lot of instances. For example, just think of a game that automatically pauses when you leave the app. Setting this up takes three steps, and Paul tells you all about it.
That’s it for day 87! We’ll keep moving forward with Flashzilla for the upcoming days, so stay tuned as tomorrow we’ll learn how to build a card view. Until then!
100 Days of SwiftUI – Day 87