设为首页 加入收藏

TOP

Type '' cannot conform to protocol '' because it has requirements that cannot be satisfied
2019-08-26 06:57:19 】 浏览:30
Tags:Type ' cannot conform protocol because has requirements that satisfied

 

我有一个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类不能实现使用仅向前声明的类的协议。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇根据图片URL获取图片的尺寸【Swif.. 下一篇iOS崩溃日志ips文件解析

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目