I have a problem in my code that I overdid until the following (stupid) example
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; __block NSString *a = @"-1"; [array enumerateObjectsUsingBlock:^(id whoCares, NSUInteger idx, BOOL *stop) { a = [NSString stringWithFormat:@"%@ %d", a, idx]; NSLog(@"%@", a); }]; NSLog(@"%@", a);
This code works, but if I comment on the first NSLog (inside the block), the code will work. But if I changed the format string to the next
a = [NSString stringWithFormat:@"%d", idx];
then the code works fine without NSLog inside the block.
What's going on here? I hope I'm just misunderstanding something.
source share