[英]How to get notified when enumerateLinesUsingBlock is completed
Is there any way to notify when a enumerateLinesUsingBlock
is completed? 有什么方法可以通知
enumerateLinesUsingBlock
完成吗? Please check below code. 请检查以下代码。 I am calling
createFastSearchData
method with chunk by chunk data in a while loop and inside that taking each lines and processing it. 我在while循环中用逐块数据调用
createFastSearchData
方法,并在其中获取每一行并对其进行处理。 In while condition I am checking the length of the main string and I want to continue untill it completes the total length. 在while条件下,我正在检查主字符串的长度,我想继续直到它完成总长度。 So I want to make sure that
enumerateLinesUsingBlock
is completed before the while loop trigger again. 因此,我想确保在再次触发while循环之前,完成
enumerateLinesUsingBlock
操作。
while(<checking the length of the mainstring>){
[self createFastSearchData:string];
}
- (void)createFastSearchData:(NSString *)newChunk{
[newChunk enumerateLinesUsingBlock:^(NSString * line, BOOL * stop)
{}];
}
Added: 添加:
I am working with blocks and finding difficulty to understand the actual flow. 我正在使用积木,发现难以理解实际流程。 Please check the below code.
请检查以下代码。 I want to call
fetchCSVData
method by passing different values in an array filesToBeFetchedWhat
. 我想通过在数组
filesToBeFetchedWhat
传递不同的值来调用fetchCSVData
方法。 I want to make sure that, fetchCSVData
should not overlap. 我想确保
fetchCSVData
不应该重叠。 How can I do that? 我怎样才能做到这一点? Please help
请帮忙
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
for (int i = 0; i < filesToBeFetched.count; i++) {
[applicationDelegate fetchCSVData:[filesToBeFetched objectAtIndex:i]];
}
}
dispatch_async( dispatch_get_main_queue(), ^{
NSLog(@"Fetching is done *********************");
});
});
To answer the first part of the question: 要回答问题的第一部分:
All enumerate...UsingBlock
methods don't work asynchronously. 所有
enumerate...UsingBlock
方法不能异步工作。
Regarding the added part: 关于增加的部分:
Assuming fetchCSVData
works also synchronously, that's the preferred way to process the data 假设
fetchCSVData
也可以同步工作,那是处理数据的首选方式
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
for (int i = 0; i < filesToBeFetched.count; i++) {
[applicationDelegate fetchCSVData:[filesToBeFetched objectAtIndex:i]];
dispatch_async( dispatch_get_main_queue(), ^{
NSLog(@"Fetching is done *********************");
});
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.