Showing posts with label NSTimer. Show all posts
Showing posts with label NSTimer. Show all posts

Saturday, May 7, 2016

Timers

In this example when startTimer function is called it creates a timer that fires every second repeatedly. Every time the timer fires it makes a call to the notifyUiToUpdate function.
class Timer {
    
    private var _timer: NSTimer!

    func startTimer() {
        _timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, 
            selector: #selector(notifyUiToUpdate), userInfo: nil, repeats: true)
    }
    
    func stopTimer() {
        _timer.invalidate()
    }
    
    @objc func notifyUiToUpdate() {
        NSNotificationCenter.defaultCenter().postNotification(
            NSNotification(name: "updateView", object: nil))
    }
}


(Swift 2.2)

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...