Search code examples
iosswiftprotocols

How to use multiple protocols in Swift with same protocol variables?


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

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(){

        }
    ...

    }

Solution

  • 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.