Not sure if this is the right title for this question or not..anyways,
I have an array of dictionaries and I am iterating through the dictionaries, passing in a block that gets executed sometimes in the future (asynchronous) and saving the result in a dictionary. Here’s my method:
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {
NSLog(@"%@", info);
NSMutableDictionary *images = [NSMutableDictionary dictionaryWithCapacity:[info count]];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
for (NSDictionary *dict in info) {
NSURL *assetURL = [dict objectForKey:UIImagePickerControllerReferenceURL];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSString *filename = asset.defaultRepresentation.filename;
UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
[images setObject:filename forKey:image];
}
failureBlock:^(NSError *error) {
[SVProgressHUD dismissWithError:@"Error occured."];
}
];
}
NSLog(@"%@", images);
[library autorelease];
[self dismissImagePickerVC];
}
Ofcourse, at the end of this method, images is empty, but my question is, how can I get a call back when all the blocks for each iteration has been executed?
Thansk
From Apple’s documentation:
When enumeration is done, your first block will see
asset == nil.