为什么我的嵌套类不满足我的协议要求?

时间:2017-05-23 15:57:27

标签: swift swift-protocols

我在游乐场中有以下协议定义:

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提出的解决方案,如果我的类型实际上并不匹配,我认为可以使用,但据我所知,StringString那么这里发生了什么?为什么我的财产不满足协议要求?

0 个答案:

没有答案