简体   繁体   English

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

[英]How do I update my imageResponseSerializer from Alamofire to the 3.0 version?

I have an imageResponseSerializer that I built following this tutorial :http://www.raywenderlich.com/85080/beginning-alamofire-tutorial我有一个按照本教程构建的 imageResponseSerializer:http ://www.raywenderlich.com/85080/beginning-alamofire-tutorial

I honestly don't really know how it works, so I was wondering if someone could help me update it to something that will work with Alamofire 3.0.老实说,我真的不知道它是如何工作的,所以我想知道是否有人可以帮助我将其更新为适用于 Alamofire 3.0 的东西。 Here is my code:这是我的代码:

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)
    }
}

Thanks谢谢

Instead of building your own image response serialization, you should switch over to using AlamofireImage .您应该切换到使用AlamofireImage ,而不是构建自己的图像响应序列化。 We built it so you wouldn't have to!我们构建了它,因此您不必这样做! 😉 😉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以将Alamofire更新到版本4,并且在我的应用程序中仍然支持iOS 8吗? - Can I update Alamofire to version 4 and still support iOS 8 in my app? 我如何从AlamoFire退货? - How do I return something from AlamoFire? 如何将我的类对象转换为 Alamofire 的 JSON - How do I convert my class object into JSON for Alamofire 如何从 Alamofire 错误中获取潜在错误? - How do I get at the underlying Error from an Alamofire error? Alamofire / AlamofireObjectMapper-如何从responseObject打印错误json? - Alamofire / AlamofireObjectMapper - How do I print error json from responseObject? 我的旧项目将Alamofire更新到版本4.0时遇到错误 - Faced error during update Alamofire to version 4.0 for my old project 如何在Swift 4中从Alamofire解析数据 - How can I parse my data from Alamofire in Swift 4 在发布新的应用程序更新时,如何在 iTunesConnect 中复制我之前版本中的“此版本中的新功能”元数据? - How do I copy "What's new in this version" metadata from my previous release in iTunesConnect while releasing a new app update? 我已将我的应用程序从swift 2.3升级到swift 3.0,在解决有关上载请求的Alamofire问题时,我遇到了一个大问题 - I have upgraded my app from swift 2.3 to swift 3.0, i am facing a big issue in resolving Alamofire issues regarding upload request 如何在不发布其他版本的情况下更新应用程序的内容? - How do I update the content of my app without releasing another version?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM