Mailcoreには、添付ファイルをダウンロードし、ダウンロードの進行状況を返すパラメーターとしてブロックを受け入れるクールなメソッドがあります。
- (CTCoreAttachment *)fetchFullAttachmentWithProgress:(CTProgressBlock)block;
CTProgressBlock は次のように定義されます。
typedef void (^CTProgressBlock)(size_t curr, size_t max);
したがって、通常は次のように使用します。
//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);
}];
問題は、この最後のメソッドがメインの UI クラスによって呼び出され、FileBucket.m
このクラスが多くの異なる UI 要素の多くの添付ファイルを順番に取得していることです。FileBucket.m
このコールバック メソッドで、この進行状況がどのアタッチメントに属しているかを報告したいと考えています。つまり、次のようなものが必要です。
// 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);
}];
これは説明/図解するのが難しいことを知っています..もう1つの追加事項:この進行状況がどのアタッチメントに関するものかを認識しています..しかし、コールバックブロックが呼び出されるたびAttachmentDownloader.m
にそれを戻したいだけです。FileBucket.m