Wie gebe ich eine Variable aus einem Block innerhalb einer Methode zurück?
Angenommen, ich habe diese Methode, bei der eine URL ein UIImage zurückgibt:
- (void)getUIImageFromURL:(NSURL *)URL {
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *imageOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
imageOperation.responseSerializer = [AFImageResponseSerializer serializer];
[imageOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
return (UIImage *)responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[imageOperation start];
}
Aber es gibt mir immer wieder diesen Fehler:
Inkompatible Blockzeigertypen, die 'UIImage * (^) (AFHTTPRequestOperation * __ strong, _ sendenstarke id) 'zu Parameter vom Typ' void (^) (AFHTTPRequestOperation *_strong, __strong id) '
Ich bin ein bisschen neu in Blocks, also gehe ich das vielleicht komplett rückwärts an. Wie würde ich eine solche Methode am besten implementieren?