关于协议组成的快速了解,“&”和“”之间有什么区别

问题描述

我有一个问题

迅速

class Card : Equatable & customstringconvertible

class Card : Equatable,customstringconvertible

我认为这里正在做同样的事情。 有什么不同?

解决方法

protocols的Swift文档中,我认为&主要用于您要求接受多种协议的变量,例如:

func wishHappyBirthday(to celebrator: Named & Aged) {
    print("Happy birthday,\(celebrator.name),you're \(celebrator.age)!")
}

如果要采用自定义结构/类以使用多种协议,则可以使用,

struct SomeStructure: FirstProtocol,AnotherProtocol {
    // structure definition goes here
}