问题描述
迅速
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
}