Even though ClassA does not have a direct reference to ClassC. If we inject the same reference of b that ClassA has into ClassC why does ClassC not get retained if it saves this reference to b? Why does this only get retained if we create a reference in ClassA to ClassC directly?
class ClassA {
var b: ClassB?
func someFunc() {
let b = ClassB()
self.b = b
let c = ClassC(b: b)
c.doSomething()
}
}
class ClassB {}
class ClassC {
private let b: ClassB
init(b: ClassB) {
self.b = b
}
func doSomething() {
print("doSomething")
}
deinit {
print("C deinit")
}
}
let a = ClassA()
a.someFunc()