我想制作一个 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)'