weak_delegate - ApplebaumIan/BitbucketAPI GitHub Wiki

Weak Delegate

Delegates should be weak to avoid reference cycles.

  • Identifier: weak_delegate
  • Enabled by default: Enabled
  • Supports autocorrection: Yes
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: warning

Non Triggering Examples

class Foo {
  weak var delegate: SomeProtocol?
}

class Foo {
  weak var someDelegate: SomeDelegateProtocol?
}

class Foo {
  weak var delegateScroll: ScrollDelegate?
}

class Foo {
  var scrollHandler: ScrollDelegate?
}

func foo() {
  var delegate: SomeDelegate
}

class Foo {
  var delegateNotified: Bool?
}

protocol P {
 var delegate: AnyObject? { get set }
}

class Foo {
 protocol P {
 var delegate: AnyObject? { get set }
}
}

class Foo {
 var computedDelegate: ComputedDelegate {
 return bar() 
} 
}

Triggering Examples

class Foo {
  ↓var delegate: SomeProtocol?
}

class Foo {
  ↓var scrollDelegate: ScrollDelegate?
}