Swift类不符合带有错误处理的Objective-C协议
发布时间:2020-12-14 05:34:05 所属栏目:百科 来源:网络整理
导读:我有Objective-C协议 @protocol SomeObjCProtocol- (BOOL) doSomethingWithError: (NSError **)error;@end 和Swift一样 class SwiftClass : SomeObjCProtocol{ func doSomething() throws { }} 编译器给我一个错误 Type ‘SwiftClass’ does not conform to
我有Objective-C协议
@protocol SomeObjCProtocol - (BOOL) doSomethingWithError: (NSError **)error; @end 和Swift一样 class SwiftClass : SomeObjCProtocol { func doSomething() throws { } } 编译器给我一个错误
有没有解决方法如何摆脱这个错误?
有两个问题:
> Swift 2 maps func doSomething()抛出Objective-C方法 有两种可能的解决方案: 解决方案1:将Objective-C协议方法重命名为 @protocol SomeObjCProtocol - (BOOL) doSomethingAndReturnError: (NSError **)error; @end 解决方案2: @objc(doSomethingWithError:) func doSomething() throws { // Do stuff } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |