上QQ阅读APP看书,第一时间看更新
Class-only protocols
If a protocol is to apply to types that are assumed to use reference semantics (rather than being passed by value), then we can create a class protocol that restricts its use to classes:
protocol ClassyProtocol: class
{
func addClassToClassesList() // or whatever
}
Any attempt to declare a value type, whether struct, Int or any other, will be met with a compiler error.