首页 > 解决方案 > 如何在 swift 类中实现目标 C 协议?

问题描述

@protocol LibraryPaymentStatusProtocol <NSObject>
@required
-(void)paymentStatus:(NSString*)message;
@optional
-(void)onError:(NSException *)exception;
-(void)tryAgain;
-(void)cancelTransaction;
@end

我想在我的 swift 类中实现这个协议。该协议存在于库内的 BDViewController.h 文件中。我在我的 swift 项目中成功导入了该库,但无法访问此协议。我还缺少什么?提前致谢。

在我的 Swift 类中,我只想像下面的普通协议一样实现

class mainTabViewController: LibraryPaymentStatusProtocol {

// MARK : - Payment status protocol method
    func paymentStatus(_ message: String!) {
      
    }

}

标签: objective-cswiftswift-protocols

解决方案


在桥接头中添加这一行

#import "BDViewController.h"

也许它会解决你的问题。让我知道它是否有帮助。


推荐阅读