Type '' cannot conform to protocol '' because it has requirements that cannot be sat
Posted jukaiit
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Type '' cannot conform to protocol '' because it has requirements that cannot be sat相关的知识,希望对你有一定的参考价值。
我有一个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 sat的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot配置FastJson报错'Content-Type' cannot contain wildcard type '*'
weak cannot be applied to non-class type '.......'
TypeError:Cannot read property 'type' of undefined
Cannot find module '../**/**/****' or its corresponding type declarations.
Cannot convert value of type 'java.lang.String' to required type 'javax.sql.DataSource