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