有人可以帮助我,我正在尝试实现Alamofire图像响应序列化方法:imageResponseSerializer,
这是我的代码:
extension Alamofire.Request {
class func imageResponseSerializer() -> ResponseSerializer<UIImage, NSError> {
return ResponseSerializer<UIImage, NSError> { request, response, data, error in
guard let validData = data else {
let failureReason = "Data could not be serialized. Input data was nil."
let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
return .Failure(error)
}
if let image = UIImage(data: validData, scale: UIScreen.mainScreen().scale) {
return Result<UIImage, NSError>.Success(image)
}
else {
return .Failure(Error.errorWithCode(.JSONSerializationFailed, failureReason: "Unable to create image."))
}
}
}
func responseImage(completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<UIImage, NSError>) -> Void) -> Self {
return response(responseSerializer: Request.imageResponseSerializer(), completionHandler: { request, response, result in
completionHandler(request, response, result)
})
}
}
错误:无法调用非函数类型的值'NSHTTPURLResponse?'
我正在使用:Xcode 7.0.1,Swift 2和Alamofire 3.0.0-beta.3
谢谢,