I want to download image from url async but im unable to download im getting error Cannot invoke URLWithstring with an argument list of type'(url:$T3,(UIImage,NSError))->void . I am newer in iOS. Please help
user=array.objectAtIndex(indexPath.row).objectForKey("thumbnail_standard") as NSString
downloadImage(url: NSURL.URLWithString(user)) { (var image:UIImage, var error:NSError) -> Void in
println(image)
}
func downloadImage(url: NSURL, handler: ((image: UIImage, error: NSError!) -> Void)) {
var imageRequest: NSURLRequest = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(imageRequest,
queue: NSOperationQueue.mainQueue(),
completionHandler:{response, data, error in
handler(image: UIImage(data: data), error: error)
})
}
In my opinion, your error message says that the function that is supposed to be invoked is not same as how you defined.
why don't you try
downloadImage(url: NSURL.URLWithString(user)) { (var image:UIImage, var error:NSError!) -> Void in // exclamation added
println(image)
}
rather than
downloadImage(url: NSURL.URLWithString(user)) { (var image:UIImage, var error:NSError) -> Void in
println(image)
}
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.