8

誰かがこのエラーを説明できますか?なぜこれが閉鎖で機能するのですか?

「B」クラス内で「Test」を「A」に変更すると、両方のケースですべてが機能します。

ベータ7

protocol Test {
    func someFunc() -> String
    var someClosure: () -> Int { get }
}

class A: Test {
    func someFunc() -> String {
        return "A String"
    }

    var someClosure: () -> Int {
        return {
            return 2
        }
    }
}

class B {
    let a: Test
    let aString: () -> String
    let aInt: () -> Int

    init(a: Test){
        self.a = a

        aString = a.someFunc // Error: Partial application of protocol method is not allowed
        aInt = a.someClosure // Works fine
    }
}

アップデート

また、ここに私の奇妙なセグメンテーション違反コレクションがあります https://gist.github.com/aleksgapp/795a2d428008bdfa4823

何か考えがある場合は、遠慮なくコメントしてください。

4

2 に答える 2