I'm trying to display an image returned from AFImageRequestOperation ImageRequestOperationWithRequest: but it appears that the image is only available inside the success block. I've tried saving it to a class instance variable but when I NSLog it, it shows up as null. However, when I NSLog the same instance variable inside the success block, after setting it with the retrieved UIImage, it actually shows a hexadecimal value (as expected). Any help here is greatly appreciated.
Here's the code where issue occurs:
imageRequest = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] success:^(UIImage *image) {
globalImage = image; // trying to have accessible image outside of success handler
[self setImageThumbImage:image]; trying to set image that class will use
NSLog(@"Image is: %@", self.albumThumbImage); // logs an actual value
imageRequest = nil;
}];
[albumImageRequest start];
NSLog(@"The second albumThumbImage retrieval returns: %@", globalImage); // logs null
return self;
}
Why not just use the added methods to UIImageView provided by AFNetworking?
From the git page:
I know this doesn't answer your question directly though it seems to achieve what you are looking to do in a much simpler manner.