使用通过协议组合声明的var符合协议

时间:2017-11-06 16:05:02

标签: swift

在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被声明为符合SpeaksGermanSpeaksFrench,我希望IHaveAPolyglotSpeaker符合任何HasGermanSpeaker或{{1}协议。

0 个答案:

没有答案