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.
https://stackoverflow.com/questions/66147175/swift-lazy-property-initialization-circular-reference-compilation-error February 11, 2021 at 08:35AM
没有评论:
发表评论