Both this declaration
protocol SomeProtocol : AnyObject {
}
and this declaration
protocol SomeProtocol : class {
}
<
In the Swift programming language guide for protocols, under the Class-Only Protocols section. It only mentioned AnyObject
, but not class
.
You can limit protocol adoption to class types (and not structures or enumerations) by adding the AnyObject protocol to a protocol’s inheritance list.
protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {
// class-only protocol definition goes here
}
For that reason, I will suggest using AnyObject
over class
for new code or new project. Other than that, I don't see any obvious difference between them.