Is there a native language feature for inline selectors in Swift? If not, is there an elegant pattern for this?
For example, an NSTimer using a Selector. This is a way you can do it without any inline function or block:
var timer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: "update", userInfo: nil, repeats: false)
@objc func update() {
print("timer up")
}
I would rather have something like this. This is a concept and does not compile.
var timer = NSTimer.scheduledTimerWithTimeInterval(2,
target: self,
selector: { println("timer up") }, // What can I do here?
userInfo: nil,
repeats: false)
This is similar to this question asked about inline selectors in Objective C.