From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Timer accuracy

Timer accuracy

- [Instructor] It's in the docks but you might not know how inaccurate timer objects can be if you're trying to show the time. Let's look at that inaccuracy and how to work around it. You'll find in the exercise file on git hub a starter project where I've put together a demo app with three labels and a button. We'll compare two ways of showing a time on a timer. I've also set up a basic timer for you. At top I declare a timer and and interval and in action for the button I set up a timer. If you're not familiar with timers, when running they're in a state called valid. If the timer is valid, I'll invalidate it shutting the timer off. If the timer isn't valid I'll start a new one. There's several ways of using timer objects. Since I like to start them immediately, I tend to use the schedule timer class method, adding the interval here and making a repeating timer. The timer has a closure on it. This closure fires once every interval, having a parameter of timer which is where we're…

Contents