Can anyone explain why the following code will result in a circular reference error while compiling?
class Foo {
let closure: ()->()
func someFunc() {}
init(closure: @escaping ()->()) {
self.closure = closure
}
}
class Bar {
lazy var foo = Foo { [weak self] in // Circular Reference error here!
self?.foo.someFunc()
}
}
However if I change it to:
class Bar {
lazy var foo: Foo = {
return Foo { [weak self] in
self?.foo.someFunc()
}
}()
}
then there is no circular reference error anymore.
I'm confused why one would cause an error, and the other would not.