I created a two dimensional array using one nsmutablearray, and there is a method:
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger row, NSUInteger column, BOOL *stop))block
{
[self.internalArray enumerateObjectsUsingBlock:^(id obj, NSUInteger rowIdx, BOOL *stopRow){
NSMutableArray *rowArray = obj;
[rowArray enumerateObjectsUsingBlock:^(id obj, NSUInteger columnIdx, BOOL *stopColumn){
block(obj, rowIdx, columnIdx, stopColumn);
}];
}];
}
I noticed that if the ‘block’ sets stopColumn to YES, then I need a way to notify the outer block that stopRow should be YES as well, I’m not sure if I can:
- use just one BOOL *stop instead of stopRow and stopColumn (as I am using ARC), or
- add a BOOL isStop inside outer block and inner block can set it to stopColumn?
This should work:
A block should capture all variables that its body uses, including the
stopRowpointer. Since you are not modifying the pointer itself, only the data to which it points, you do not need to do anything else (if you needed to modify the pointer itself, you’d need an additional temporary variable declared as__block).