![](/img/trans.png)
[英]How do I implement a Swift protocol with a generic constrained type property?
[英]How would I implement this protocol in swift?
如果我有一个名为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
您必须在协议之前列出超类(或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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.