为什么我不能初始化这个结构?

时间:2017-07-25 15:52:44

标签: swift generics swift-structs

我想制作一个Swift Error来描述来自Objective-C的变量的Type是如何错误的。以下是我尝试定义struct

的方法
public struct UnexpectedResultTypeError<Expected, Actual>: Error {
    let expected: Expected.Type
    let actual: Actual.Type

    init(expected: Expected.Type, got actual: Actual.Type) {
        self.expected = expected
        self.actual = actual
    }
}

我认为这很好,但现在我无法初始化它:

UnexpectedResultTypeError<String, Any>(expected: String.self, got: type(of: serializedResult))
Cannot invoke initializer for type 'UnexpectedResultTypeError<String, Any>' with an argument list of type '(expected: String.Type, got: Any.Type)'

0 个答案:

没有答案