0

我想制作一个 SwiftError来描述Type来自 Objective-C 的变量是如何错误的。这是我尝试定义的方式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)'
4

0 回答 0