Skip to content

Files

Latest commit

 

History

History
38 lines (19 loc) · 750 Bytes

anyobject_protocol.md

File metadata and controls

38 lines (19 loc) · 750 Bytes

Pattern: Use of class instead of AnyObject

Issue: -

Description

Prefer using AnyObject over class for class-only protocols.

Examples of correct code:

protocol SomeProtocol {}


protocol SomeClassOnlyProtocol: AnyObject {}


protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}


@objc protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}

Examples of incorrect code:

protocol SomeClassOnlyProtocol: class {}


protocol SomeClassOnlyProtocol:class, SomeInheritedProtocol {}


@objc protocol SomeClassOnlyProtocol:class, SomeInheritedProtocol {}

Further Reading