在Swift中可能有这样的事吗?
protocol SpeaksGerman {
func speakGerman()
}
protocol SpeaksFrench {
func speakFrench()
}
protocol HasGermanSpeaker {
var speaker: SpeaksGerman! {get}
}
protocol HasFrenchSpeaker {
var speaker: SpeaksFrench! {get}
}
class IHaveAPolyglotSpeaker: HasGermanSpeaker {
var speaker: (SpeaksGerman & SpeaksFrench)!
}
由于var speaker
被声明为符合SpeaksGerman
和SpeaksFrench
,我希望IHaveAPolyglotSpeaker
符合任何HasGermanSpeaker
或{{1}协议。