我正在使用 Alamofire用于发送请求和处理响应。我创建了一个使用 Alamofire.Result
的简单类输入:
class MyHandler {
private var _result: Alamofire.Result
init(result: Alamofire.Result) {
//ERROR: Cannot assign value of type 'Result<_,_>' to type 'Result'
self._result = result
}
}
我的代码中出现了如上所示的奇怪错误。这是 source code的 Alamofire.Result
.这是一个枚举 enum Result<Value, Error: ErrorType>
.
我正在使用相同的 Alamofire.Result
输入我的类(class) self._result
& result
通过初始值。
为什么会出现此错误?看起来编译器认为它们不是同一类型...我的 xcode 版本是 7.3.1。这是 xcode 错误吗?
最佳答案
AlamoFire.Result
是具有两个占位符的泛型
public enum Result<Value, Error: ErrorType> { ... }
您可以为具体类型声明您的类 占位符,例如
class MyHandler {
private var _result: AlamoFire.Result<Int, NSError>
init(result: AlamoFire.Result<Int, NSError>) {
self._result = result
}
}
但您更有可能想要声明一个泛型类:
class MyHandler<Value, Error: ErrorType> {
private var _result: AlamoFire.Result<Value, Error>
init(result: AlamoFire.Result<Value, Error>) {
self._result = result
}
}
关于ios - Alamofire:错误:无法将类型 'Result<_,_>' 的值分配给类型 'Result',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37195110/