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

前端 未结 6 1940
一整个雨季
一整个雨季 2020-12-02 14:30

Both this declaration

protocol SomeProtocol : AnyObject {
}

and this declaration

protocol SomeProtocol : class {
}
<         


        
6条回答
  •  半阙折子戏
    2020-12-02 14:56

    This was answered by an official Swift dev (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.

提交回复
热议问题