I have a method:
- (void)myMethod:(NSError *)error
{
[[self.data allKeys] enumerateUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
__block NSString *channelName = obj;
NSArray *subArray = [self.data objectForKey:obj];
[subArray enumerateUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
Wrapper *wrapper = obj;
[wrapper handleError:error forChannel:channelName];
}];
}];
}
1) Do I need to use different names for parameters obj, idx and stop for the inner block?
2) Do I need or not need to define channelName as __block?
3) Do I need to define a weak self outside all blocks and use it in blocks?
edit:
channelName is used by inner block, and is passed to the handler block.
Your blocks run synchronously and are not copied to the heap, so there’s nothing extra you have to do. There’s no special memory management to consider (i.e., no weak references required) and you don’t need the
__blockqualifier (unless the inner block needs to modify an outer variable).On other words, all you have here is a plain old nested for-loop. The memory management is no different than an actual for-loop.