This isn't critical, and there are workarounds, but it is perplexing.
See the minimal example below. I'm referring to an initialized property, but before calling super.init(). Why does the indicated statement below have a compile error? Is there something special about using the property in the right hand of an expression versus the left hand?
I looked through the Swift language guides and couldn't find anything relevant. Is the swift compiler screwing up here, or is there something about properties, self, and init that I'm missing? Or should all references to "myProperty" be in error before calling super.init?
(Note it doesn't matter if the property is a constant (with 'let') or if the property is another type, like an Int - the same thing happens.)
class MyClass : NSObject {
var myProperty: Bool
override init() {
myProperty = true
if myProperty { /* this is ok */ }
if myProperty || true { /* this is ok */ }
if true || myProperty { /* this is NOT ok! ('self used before super.init') - WHY? */ }
super.init()
if true || myProperty { /* now this is ok */ }
}
}