码迷,mamicode.com
首页 > 其他好文 > 详细

Type '' cannot conform to protocol '' because it has requirements that cannot be satisfied

时间:2018-08-12 17:29:55      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:tis   hat   不能   cti   tcl   object   nbsp   can   包含   

 

我有一个Objective-C协议,我试图在Swift类中实现。例如:

@class AnObjcClass;

@protocol ObjcProtocol <NSObject>
    - (void)somethingWithAnArgument:(AnObjcClass *)arg;
@end

当我尝试在这样的Swift类中符合它时:

@objc class SwiftClass: NSObject, ObjcProtocol {
    // ...
}

我得到以下可怕的编译器错误:

Type ‘‘ cannot conform to protocol ‘‘ because it has requirements that cannot be satisfied

 

我该如何解决这个问题?

 

 

解决方案:

 

确保该协议引用的任何类都包含在桥接头中。

当协议中使用的某个类型(协议本身,返回类型,参数类型)未包含在Swift桥接头中时,会发生此错误。

由于@class AnObjcClass前向声明,Objective-C类可以愉快地实现此协议,但似乎Swift类不能实现使用仅向前声明的类的协议。

Type '' cannot conform to protocol '' because it has requirements that cannot be satisfied

标签:tis   hat   不能   cti   tcl   object   nbsp   can   包含   

原文地址:https://www.cnblogs.com/jukaiit/p/9463077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!