次の3つのコードが同じことをしているのをどこかで見ました。
ループの使用:
BOOL stop = 0;
for (int i = 0 ; i < [theArray count] ; i++) {
NSLog(@"The object at index %d is %@",i,[theArray objectAtIndex:i]);
if (stop)
break;
}
高速列挙の使用:
int idx = 0;
BOOL stop = 1;
for (id obj in theArray) {
NSLog(@"fast emuration approch @ x %d is %@",idx,obj);
if (stop)
break;
idx++;
}
ブロックの使用:
[theArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"the block approch at x %d is %@",idx,obj);
}];
しかし、私が理解していないのは-
- ブロックアプローチで外部から停止を設定するにはどうすればよいですか?
- ブロックアプローチでidxを設定するにはどうすればよいですか?
- BOOL宣言は、ブロックアプローチでは異常です。なぜですか?(ブロック内の値も変更できないので、そのような宣言のせいですか?)