How to download image with AFNetworking 2.0?

后端 未结 3 932
臣服心动
臣服心动 2020-12-04 11:57

Appareantly there is no AFImageRequestOperation, but only AFImageResponseSerializer and frankly I don\'t get it or maybe I\'m just looking too long

3条回答
  •  感情败类
    2020-12-04 12:31

    For people using AFNetworking in Swift, above solution can be written as below

        let requestOperation : AFHTTPRequestOperation = AFHTTPRequestOperation(request: urlRequest)
        requestOperation.responseSerializer = AFImageResponseSerializer()
    
        requestOperation.setCompletionBlockWithSuccess({ (requestOperation, responseObject) in
           print(responseObject)
            _imageView.image = responseObject as? UIImage
    
        }) { (requestOperation, error) in
           print(error)
        }
        requestOperation.start()
    

提交回复
热议问题