What's the difference between a protocol extended from AnyObject and a class-only protocol?

class, protocols, swift

Solution

This was answered by an official Swift developer (Slava_Pestov) on the Swift forums. Here is the summary:

You should use `AnyObject` (`protocol SomeProtocol: AnyObject`).

`AnyObject` and `class` are equivalent. There is no difference.

`class` will eventually be deprecated.

Problem

Both this declaration ``` protocol SomeProtocol : AnyObject { } ``` and this declaration ``` protocol SomeProtocol : class { } ``` seem to make it so that only classes can conform to this protocol (i.e. that the instances of the protocol are references to objects), and have no other effects. Is there any difference between them? Should one be preferred over the other? If not, why is there two ways to do the same thing? I am using the latest released Xcode 6.3.1.

Original source