I have this class
class Foo{
public class func barFunction(){}
public class func barFunction2(){}
public class func barFunction3(){}
}
You can use NSTimer
to call a selector once:
NSTimer.scheduledTimerWithTimeInterval(0, target: self, selector: Selector("barFunction"), userInfo: nil, repeats: false)
Using closures and dictionary:
let options = [
"bar1": { Foo.barFunction1() },
"bar2": { Foo.barFunction2() },
"bar3": { Foo.barFunction3() }
]
// Ways of calling the closures
options["bar2"]!()
options["bar1"]?()
let key = "bar3"
if let closure = options[key] {
closure()
}