首页 > 解决方案 > Swift:具有约束的关联类型的协议产生“非法指令”

问题描述

我有以下代码:

protocol Transformable {
    associatedtype OutputType
    func transform() -> OutputType
}

protocol AB {
    associatedtype A: Transformable where A.OutputType == B
    associatedtype B: Transformable where B.OutputType == A
}

我得到了错误:

由于信号而命令失败:非法指令:4

没有更多关于错误是什么的细节。

代码确实感觉有点奇怪,但问题是什么?

标签: iosswiftgenericsprotocolsassociated-types

解决方案


推荐阅读