Mailcore has a cool method that downloads an attachment and accepts a block as a parameter to return download progress:
- (CTCoreAttachment *)fetchFullAttachmentWithProgress:(CTProgressBlock)block;
where CTProgressBlock is defined as
typedef void (^CTProgressBlock)(size_t curr, size_t max);
so typically I would use it like so:
//AttachmentDownloader.m
int fileNum = x; // explained later
CTCoreAttachment* fullAttachment =
[attachment fetchFullAttachmentWithProgress:^(size_t curr, size_t max) {
NSLog(@"::: this is curr: %zu", curr);
NSLog(@"::: this is max: %zu\n\n", max);
}];
the problem is that this last method is called by my main UI class FileBucket.m
and this class is in turn fetching many attachments for many different UI elements in sequence. I would like this callback method to report back to FileBucket.m
which attachment this progress belongs to.. so in other words i want something along the lines of:
// FileBucket.m
[AttachmentDownloader runMultiple:attachmentTree
withProgress:^(size_t curr, size_t max, int fileNum) {
NSLog(@"::: this is curr: %zu", curr);
NSLog(@"::: this is max: %zu\n\n", max);
NSLog(@"::: this progress belongs to element %d", fileNum);
}];
I know this is hard to explain/illustrate.. one extra thing: AttachmentDownloader.m
is aware of which attachment this progress is about.. but it just wants to pass it back to FileBucket.m
every time the callback block is called.