Reputation: 19969
Trying to make a fix in a pre-existing project with Alamofire but I am getting an error.
The code in question is:
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 get 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 msg is telling me. The _
I thought means unnamed parameters.
How would I download an image via Alamofire?
can Cmd + Click and "Open Image In New Tab" to get full-sized image
Upvotes: 3
Views: 4538
Reputation: 319
What is important in these cases is to cancel the request in progress for the cell, because if not properly canceled, a mistaken image can be shown.
I have developed a small and straightforward CocoaPods library to work with Alamofire and Images. The library just handles the canceling automatically whenever a new request is made for the same image view object.
CocoaPods is a great way of addressing your library dependencies needs. It is easy to install once, and easy to add and update dependencies to your projects.
The library is open source and can be found at https://github.com/gchiacchio/AlamoImage
It has great documentation with examples, so you will be enjoying it in minutes.
I have it working in a couple of project myself, including collection views and scrolling.
Upvotes: 0
Reputation: 14845
Try this:
Alamofire.request(.GET, imageURL).response() {
(_, _, data, _) in
let image = UIImage(data: data! as! NSData)
tableViewCell.backgroundImageView.image = image
}
Response need to be called with empty parameters and a completion handler.
Upvotes: 4