如果我有一个名为myIntersitital的类,我将如何在其中实现此目标c协议。任何提示将不胜感激。我只是得到'不符合协议'的错误。
夫特:
import Foundation
import GoogleMobileAds
class myInterstitial: GADCustomEventInterstitial{
//... implements here
}
Objective-c协议:
#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
答案 0 :(得分:0)
您必须在协议之前列出超类(或NSObject)。我还建议你把你的班级名称大写。
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
}
}