如何在Swift中使用具有相同协议变量的多个协议? [英] How to use multiple protocols in Swift with same protocol variables?

查看:61
本文介绍了如何在Swift中使用具有相同协议变量的多个协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迅速实现两个协议, GADCustomEventInterstitial GADCustomEventBanner .

In swift I'm implementing two protocols, GADCustomEventInterstitial and GADCustomEventBanner.

这两个协议都需要一个名为 delegate 的属性. delegate 是每种协议中的不同类型,因此会产生冲突.

Both of these protocols require a property called delegate. delegate is a different type in each protocol, and thus a conflict arises.

 class ChartBoostAdapter : NSObject, GADCustomEventInterstitial, GADCustomEventBanner, ChartboostDelegate{
        var delegate:GADCustomEventInterstitialDelegate?; // Name conflict
        var delegate:GADCustomEventBannerDelegate?; // Name conflict
         override init(){

        }
    ...

    }

推荐答案

简单的答案是您做不到.

The simple answer is that you can't.

也许一个协议依赖于另一个协议,在这种情况下,您将对代理的类型使用从属协议.

Maybe one protocol depends on another, in which case you would use the dependent protocol for the type of your delegate.

这篇关于如何在Swift中使用具有相同协议变量的多个协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆