Swift 1.2: 'self' used before super.init call -
i have code:
class someviewcontroller : uiviewcontroller { let deferred : ()->() required init(coder adecoder : nscoder) { deferred = { self.dosomething() } super.init(coder: adecoder) } func dosomething() { // things.... } }
in swift 1.2 fails compile error:
'self' used before super.init call
in pre-1.2 days, can address in number of ways such implicitly unwrapped conditionals. approach won't work longer.
i've seen other answers reference 2-stage initialization or lazy decorator, both sacrifice immutability of property. surely must solvable in swift 1.2, i'm out of ideas.
here's interim workaround:
private(set) var deferred : ()->() = { } required init(coder adecoder : nscoder) { super.init(coder: adecoder) self.deferred = { self.dosomething() } }
my thinking is, okay, did "sacrifice immutability of property", public perspective property remains immutable because setter private.