The stop flag is used as follows:
[coll enumerateUsingBlock:^(id o, NSUInteger i, BOOL *stop) { if (... check for stop ... ) { *stop = YES; return; } }];
When the enumeration block returns, the collection checks *stop . If he is YES , he ceases to be listed.
It is implemented in this way, in contrast to the return value, since it allows parallel enumeration without checking the return value of the block (which can lead to overhead). That is, in a parallel enumeration, a collection can dispatch_async() an arbitrary number of simultaneous iterations and periodically check *stop . Whenever *stop switches to YES , it stops scheduling more blocks (this also means that the stop flag is not a hard stop, and some undefined number of iterations can still be in flight).
In your iterator, you can:
BOOL stop = NO; for(...) { enumerationBlock(someObj, someIndex, &stop); if (stop) break; }
bbum
source share