Skip to content

Files

Latest commit

 

History

History
59 lines (40 loc) · 812 Bytes

weak_computed_property.md

File metadata and controls

59 lines (40 loc) · 812 Bytes

Pattern: Use of weak in computed property

Issue: _

Description

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 }
    }
}