![](/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.