I\'m trying to create an NSTimer
in Swift
but I\'m having some trouble.
NSTimer(timeInterval: 1, target: self, selector: test(), us
selector
is a word from Objective-C
world and you are able to use it from Swift
to have a possibility to call Objective-C
from Swift
It allows you to execute some code at runtime
Before Swift 2.2
the syntax is:
Selector("foo:")
Since a function name is passed into Selector
as a String
parameter("foo") it is not possible to check a name in compile time. As a result you can get a runtime error:
unrecognized selector sent to instance
After Swift 2.2+
the syntax is:
#selector(foo(_:))
Xcode's autocomplete help you to call a right method