iOS Programming Cookbook
上QQ阅读APP看书,第一时间看更新

Class-only protocols

We mentioned before that classes, structures, and enumerations could adopt protocols. The difference among them is that classes are reference types, whereas structures and enumerations are value types. If you find yourself having some specific actions that will be done only via reference types, mark it as class only. To do so, just mark it as follows:

protocol ClassOnlyProtocol: class{ 
   // class only properties and methods go here 
} 

Add a colon : and the class keyword to mark your protocol as class only.