如何将我的imageResponseSerializer从Alamofire更新到3.0版本?

时间:2015-10-08 19:22:40

标签: ios swift alamofire

我有一个按照本教程构建的imageResponseSerializer:http://www.raywenderlich.com/85080/beginning-alamofire-tutorial

老实说,我真的不知道它是如何工作的,所以我想知道是否有人可以帮助我将它更新为适用于Alamofire 3.0的东西。这是我的代码:

extension Alamofire.Request {

class func imageResponseSerializer() -> GenericResponseSerializer<UIImage> {
    return GenericResponseSerializer { request, response, data 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(data, error)
        }

        if let image = UIImage(data: validData, scale: UIScreen.mainScreen().scale) {
            return Result<UIImage>.Success(image)
        } else {
            return .Failure(data, Error.errorWithCode(.DataSerializationFailed, failureReason: "Unable to create image"))
        }

    }
}

    func responseImage(completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<UIImage>) -> Void) -> Self {
        return response(responseSerializer: Request.imageResponseSerializer(), completionHandler: completionHandler)
    }
}

由于

0 个答案:

没有答案