class ControllerU: NSObject {}protocol Robert { associatedtype T associatedtype U: ControllerT var fetcher: U { get }}class Telephone: NSObject {}class Object: Telephone {}class Turtle: ControllerObject {}class Fish: Robert { typealias T =
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 } }
我不明白为什么.任何帮助赞赏.
选择XCode“修复它”选项时,会插入“Fetcher”的存根.但是Fetcher已经有了一个类型.
现在已经在Swift 4中认识到了这一点.现在我们必须避免受具有通用约束的类型约束的关联类型.所以这并不酷
associatedtype U: Controller<T>
删除它会产生以下结果,这是有效的.
protocol Robert { associatedtype T: NSObject var fetcher: Controller<T> { get } }