[英]Class does not conform to protocol. Why?
class Controller<U: NSObject> {}
protocol Robert {
associatedtype T
associatedtype U: Controller<T>
var fetcher: U { get }
}
class Telephone: NSObject {}
class Object: Telephone {}
class Turtle: Controller<Object> {}
class Fish: Robert {
typealias T = Object
typealias U = Turtle
let x = Turtle()
var fetcher: Turtle {
return x
}
}
I don't understand why. 我不明白为什么。 Any help appreciated.
任何帮助表示赞赏。
When selecting the XCode 'fix it' option, a stub for 'Fetcher is inserted. 选择XCode“修复”选项时,将插入“提取程序”的存根。 But there is already a typealias for Fetcher.
但是Fetcher已经有一种类型别名。
This has now been recognized as a bug in Swift 4. For now we must avoid associated types constrained by types that have generic constraints. 现在,这已被认为是 Swift 4中的错误 。目前,我们必须避免关联类型受具有通用约束的类型所约束。
So this is not cool 所以这不酷
associatedtype U: Controller<T>
Removing it results in the following, which works. 删除它会产生以下效果。
protocol Robert {
associatedtype T: NSObject
var fetcher: Controller<T> { get }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.