From the course: Advanced iOS App Development: Core Motion
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Add a timer loop - iOS Tutorial
From the course: Advanced iOS App Development: Core Motion
Add a timer loop
[Instructor] You found out that pushing data to a label leads to bugs. Let's find some less direct solutions. First, we'll set a property and let a property observer set the label. Close the console. Let's make a new property. The top of our code. Define the number of steps property with a property observer to update the label. There, number of steps. Make it a explicit optional integer, so INT exclamation point equals nil. And then add the property observer with did set and we're going to make steps label dot text equal to string, format, steps. Format again integer, comma, number of steps. When the property changes, the label changes. Head back down in our code and let's comment out the assignment in the closure. The pedometer number of steps property is an NS number. You have to cast to an INT to use the use the view controller number of steps property. So under the comment, add this. Self dot number of steps equals INT pedometer data dot number of steps. Okay, we're ready to go…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.