AnyObject Protocol

Prefer using AnyObject over class for class-only protocols

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

Non Triggering Examples

protocol SomeProtocol {}

protocol SomeClassOnlyProtocol: AnyObject {}

protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}

@objc protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}

Triggering Examples

protocol SomeClassOnlyProtocol: class {}

protocol SomeClassOnlyProtocol: class, SomeInheritedProtocol {}

@objc protocol SomeClassOnlyProtocol: class, SomeInheritedProtocol {}