protocol AProtocol {
var someString: String { get }
}
class A: AProtocol {
var someString: String
init() {
someString = "A"
}
}
class B {
var myProperty: AProtocol! {
didSet {
self.doSomething()
}
}
func doSomething() {
NSLog(self.myProperty.someString)
}
}
let myB = B()
myB.myProperty = A() // infinite recursion
protocol AProtocol: class {
var someString: String { get }
}
class A: AProtocol {
var someString: String
init() {
someString = "A"
}
}
class B {
var myProperty: AProtocol! {
didSet {
self.doSomething()
}
}
func doSomething() {
NSLog(self.myProperty.someString)
}
}
let myB = B()
myB.myProperty = A() // now it worksSo basically if I don't impose the restriction AProtocol: class I will get an infinite loop. Basically when in doSomething I try access the just set property it will trigger the didSet block again (B.(myProperty.materializeForSet).(closure #1))
Can someone explain me why is this or confirm this is a bug in Swift?
Cheers