简体   繁体   中英

How would I implement this protocol in swift?

If I have a class named myIntersitital, how would I implement this objective c protocol in it. Any tips would be appreciated. I just get 'does not conform to protocol' error.

Swift:

import Foundation
import GoogleMobileAds
class myInterstitial: GADCustomEventInterstitial{
//... implements here
}

Objective-c Protocol:

#import <UIKit/UIKit.h>
#import "GADCustomEventInterstitialDelegate.h"
#import "GADCustomEventRequest.h"


    @protocol GADCustomEventInterstitial<NSObject>

    @property(nonatomic, weak) id<GADCustomEventInterstitialDelegate> delegate;


    - (void)requestInterstitialAdWithParameter:(NSString *)serverParameter
                                         label:(NSString *)serverLabel
                                       request:(GADCustomEventRequest *)request;

    - (void)presentFromRootViewController:(UIViewController *)rootViewController;

    @end

You have to list a superclass (or NSObject) before the protocols. I would also recommend you capitalize your class names.

import Foundation

class MyInterstitial: NSObject, GADCustomEventInterstitial {

    var delegate: GADCustomEventInterstitialDelegate?

    func requestInterstitialAdWithParameter(serverParameter: String!, label serverLabel: String!, request: NSObject!) {
        // implementation here
    }

    func presentFromRootViewController(rootViewController: UIViewController!) {
        // implementation here
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM