The selector is the name of the function, and the target is the object for which the function is executed. You create a selector using the syntax: #selector(<function name>)
, for example:
class MyClass { func createAction() { let action = SKAction.perform(#selector(MyClass.myActionFunction), onTarget: self) // ... } @objc func myActionFunction() { // do stuff } }
To create a selector for a function that takes arguments, use the syntax:
#selector(MyClass.myActionFunction(arg1:arg2:))
You can also do the same using a block instead of a selector:
let action = SKAction.run { [weak self] in self?.myActionFunction() }
source share