import UIKit
class ViewController: UIViewController {
var myAction: ((Int, Bool) -> Void)? = { [weak self] int, bool in
}
}
I have no idea why I'm getting this error. I thought self
should be an instance of ViewController
, how is it becoming '(ViewController) -> () -> ViewController'
?
CodePudding user response:
At the point when your property initializer runs, self
is not yet available. You'll need to use lazy loading — which is pretty easy. Just add lazy
in front of the var.
lazy var myAction: ((Int, Bool) -> Void)? = { [weak self] int, bool in
}