Learn how to implement a circular `ProgressBar` that syncs with a countdown timer in SwiftUI! This guide uses a straightforward approach to enhance your app's UI. --- This video is based on the question https://stackoverflow.com/q/64037789/ asked by the user 'Thom Sides' ( https://stackoverflow.com/u/12349248/ ) and on the answer https://stackoverflow.com/a/64039597/ provided by the user 'New Dev' ( https://stackoverflow.com/u/968155/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Circular progress bar for a countdown timer publisher SwiftUI Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Creating a Circular ProgressBar for a Countdown Timer in SwiftUI If you're designing a countdown timer in SwiftUI and want to incorporate a circular progress bar, you might be wondering how best to synchronize the two. In this guide, we’ll explore a simple yet effective way to create a circular ProgressBar that visually depicts the countdown timer's progress. We’ll cover the code structure you’ll need, as well as how to update the ProgressBar as the timer counts down. The Challenge: Updating the Circular Progress Bar When creating a countdown timer, it’s essential to ensure that the visual representation of progress is both accurate and compelling. The question at hand is: How can we effectively update a circular ProgressBar that corresponds to the countdown? One approach to enhancing the synchronization between your timer and the progress bar is through the use of SwiftUI’s @ Published properties and observers. Step-by-Step Solution 1. Modifying the TimerManager To effectively track the progress of your timer, we need to create a computed property within the TimerManager class. This computed property will calculate the progress based on the time remaining and the time selected. Here’s how you can implement the computed property: [[See Video to Reveal this Text or Code Snippet]] This computed property allows your UI to dynamically express the current progress of the countdown in your progress bar. However, simply creating this variable isn't enough; we also need to notify the UI when changes occur. 2. Triggering UI Updates Since the progress property depends on timeRemaining, which is marked with @ Published, SwiftUI will automatically observe changes and update the UI when timeRemaining changes. If you choose an alternative approach, you can manually trigger updates. Inside your .sink closure where you're managing timer updates, you can use self.objectWillChange.send() to notify observers of the impending change: [[See Video to Reveal this Text or Code Snippet]] 3. Updating the Progress Bar in the View Now that your TimerManager is set to track progress accurately, it’s time to render this in your ProgressBar. You will adjust how you pass the progress to the ProgressBar as it should no longer be a binding. Here’s how to do this in your ContentView: [[See Video to Reveal this Text or Code Snippet]] This change allows the ProgressBar to dynamically reflect the current state of the countdown timer. 4. Adjusting the ProgressBar View With this approach in mind, you will need to ensure that the ProgressBar struct is modified accordingly. Since progress is no longer a binding, you can remove the @ Binding attribute: [[See Video to Reveal this Text or Code Snippet]] By implementing these changes, the progress bar should now accurately reflect the countdown timer, providing users with a clear visual representation of their remaining time. Conclusion Integrating a circular ProgressBar with a countdown timer in SwiftUI can significantly enhance your application's user experience. By using a combination of @ Published properties and computed values, you can ensure that your UI updates as the timer progresses. Feel free to modify and expand upon this example in your own projects, and watch as your countdown timer not only tracks time but also visually engages your users through a seamless progress bar. With this guide, you should now have a strong foundation for implementing visual timers in SwiftUI applications.