![]() ![]() common) Synchronizing your timer with screen updates common is the one we want: it allows our timers to fire even when the UI is being used.įor example: let context = ["user": timer = Timer(timeInterval: 1.0, target: self, selector: #selector(fireTimer), userInfo: context, repeats: true) The easiest solution is to create the timer without scheduling it directly, then add it by hand to a runloop of your choosing. This will then get paused while the user is actively interacting with our UI, then reactivated when they stop. This happens because we’re implicitly creating our timer on the defaultRunLoopMode, which is effectively the main thread of our application. For example, if the user has their finger touching the screen so they can scroll through a table view, your regular timers won’t get fired. One common problem folks hit when using timers is that they won’t fire when the user is interacting with your app.
0 Comments
Leave a Reply. |