我将如何在 swift 中实施此协议?
How would I implement this protocol in swift?
如果我有一个名为 myIntersitital 的 class,我将如何在其中实施此 objective c 协议。任何提示将不胜感激。我刚收到 'does not conform to protocol' 错误。
Swift:
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
您必须在协议前列出一个超级class(或 NSObject)。我还建议您将 class 名称大写。
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
}
}
如果我有一个名为 myIntersitital 的 class,我将如何在其中实施此 objective c 协议。任何提示将不胜感激。我刚收到 'does not conform to protocol' 错误。
Swift:
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
您必须在协议前列出一个超级class(或 NSObject)。我还建议您将 class 名称大写。
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
}
}