有没有办法让以下内容真正起作用?
V1——“测试协议(protocol)不符合Hashable”
protocol testProtocol {
//
}
class test {
var s : Set<testProtocol>?
init(){
}
}
V2 - “协议(protocol) 'testProtocol' 只能用作通用约束,因为它具有 Self 或关联类型要求
protocol testProtocol : Hashable {
//
}
class test {
var s : Set<testProtocol>?
init(){
}
}
我假设答案是否定的——因为协议(protocol)(即使带有@objc 标签)没有足够的信息??但也许我在这里缺少某种线条或东西。
最佳答案
也许有更好的解决方案,但您可以使您的类通用:
protocol testProtocol : Hashable {
//
}
class test<P: testProtocol> {
var s : Set<P>?
init() { }
}
关于swift - 带有协议(protocol)对象的纯 swift 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29278624/