我正在快速实现两个协议(protocol),GADCustomEventInterstitial
和 GADCustomEventBanner
。
这两个协议(protocol)都需要一个名为delegate
的属性。 delegate
在每个协议(protocol)中都是不同的类型,因此会产生冲突。
class ChartBoostAdapter : NSObject, GADCustomEventInterstitial, GADCustomEventBanner, ChartboostDelegate{
var delegate:GADCustomEventInterstitialDelegate?; // Name conflict
var delegate:GADCustomEventBannerDelegate?; // Name conflict
override init(){
}
...
}
最佳答案
They are libraries/frameworks it's not my definition
那么显然你不能让同一个类同时采用这两种协议(protocol)。但你真的不需要。只需将此功能分成两个不同的类,这显然是这些协议(protocol)的设计者的意图。您应该有一个采用 GADCustomEventInterstitial 并具有它的 delegate
的类,以及另一个 采用GADCustomEventBanner
和有它的 委托(delegate)
。你有什么理由试图强制这些成为同一个类(class)?与您使用框架的所有事情一样,不要对抗框架,服从它。
关于ios - 如何在具有相同协议(protocol)变量的 Swift 中使用多个协议(protocol)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29585572/