我在游乐场中有以下协议定义:
protocol Outer {
associatedtype Nested: Inner
protocol Inner {
var property: String { get set }
}
}
以下实施:
class Test: Outer {
class Nested: Outer.Inner {
var property: String = ""
}
}
无法编译:
Playground execution failed: error: nested protocols.playground:7:11: error: type 'Test.Nested' does not conform to protocol 'Inner'
class Nested: Outer.Inner {
^
nested protocols.playground:8:13: note: candidate has non-matching type 'String'
var property: String = ""
^
Searching for the error message提出的解决方案,如果我的类型实际上并不匹配,我认为可以使用,但据我所知,String
是String
。 那么这里发生了什么?为什么我的财产不满足协议要求?