Pattern: Use of weak
in computed property
Issue: _
Adding weak
to a computed property has no effect.
Examples of correct code:
class Foo {
weak var delegate: SomeProtocol?
}
class Foo {
var delegate: SomeProtocol?
}
class Foo {
weak var delegate: SomeProtocol? {
didSet {
update(with: delegate)
}
}
}
class Foo {
weak var delegate: SomeProtocol? {
willSet {
update(with: delegate)
}
}
}
Examples of incorrect code:
class Foo {
weak var delegate: SomeProtocol? { return bar() }
}
class Foo {
private weak var _delegate: SomeProtocol?
↓weak var delegate: SomeProtocol? {
get { return _delegate }
set { _delegate = newValue }
}
}