I can't find out how to declare the following method in swift:
- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ( !error )
{
UIImage *image = [[UIImage alloc] initWithData:data];
completionBlock(YES,image);
} else{
completionBlock(NO,nil);
}
}];
}
I found this method from natashatherobot blog : http://natashatherobot.com/ios-how-to-download-images-asynchronously-make-uitableview-scroll-fast/
I would like to call same method in swift and once the asynchronous request gets the image pass it to the completionBlock.
What would you suggest ?