How to initialize let property of closure type to pointer to some method?
closures, initialization, swift
Solution
You can declare the property as implicitly unwrapped optional:
let action: (String -> ())!
That's one of the few cases when implicitly unwrapped are useful and can be safely used.
Problem
Have a look on following code ``` class Example { let action: String -> () init() { action = method //error: Variable self.action used before initialized } func method(s: String) { println(s) } } ``` I am setting property of closure type to a class method. To reference class method I need to have the single properties initialized but to have it properly inicialized I need to reference that method. How do I get out of the cycle? I know I can do something like ``` init() { action = {_ in } action = method //error: Variable self.action used before initialized } ``` but that just is not nice. The actual thing I need to do is more complex and makes much more sense bt this is the essence.