Error while using Alamofire to load image

Trying to make a fix on a pre-existing project using Alamofire, but I get an error.

Given code:

   Alamofire.request(.GET, "https://www.domain.com/demo-mobile-images/dogs-blue.jpg" ).response { (request, response, data , error) in
       tableViewCell.backgroundImageView.image = UIImage(data: data, scale:1)
    }

      

but i am getting error:

Cannot invoke 'response' with an argument list of type '((_, _, _, _) -> _)'

      

It looks like what I'm trying to call is really standard and I'm not sure what the error message is telling me. _

I thought what unnamed parameters means.

How do I upload an image via Alamofire?

edit 1 - here is a screenshot of the error

can Cmd + click and "Open Image in New Tab" to get full size image

enter image description here

+3


source to share


2 answers


Try the following:

Alamofire.request(.GET, imageURL).response() {
  (_, _, data, _) in
  let image = UIImage(data: data! as! NSData)
  tableViewCell.backgroundImageView.image = image
}

      



The response must be invoked with empty parameters and a completion handler.

+4


source


In these cases, it is important to cancel the current request for the cell because if it is not canceled properly, an erroneous image may be displayed.

I have developed a small and simple CocoaPods library to work with Alamofire and Images. The library just handles cancellation automatically on every new request for the same image viewer.

CocoaPods are a great way to meet your library dependency needs. It's easy to install once and it's easy to add and update dependencies to your projects.



The library is open source and is located at https://github.com/gchiacchio/AlamoImage

It has great documentation with examples, so you'll be enjoying it in minutes.

I am working on this project including collection view and scrolling.

0


source







All Articles