RosettaCodeData/Task/Closures-Value-capture/Objective-C/closures-value-capture.m
2023-07-01 13:44:08 -04:00

7 lines
199 B
Objective-C

NSMutableArray *funcs = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
[funcs addObject:[^ { return i * i; } copy]];
}
int (^foo)(void) = funcs[3];
NSLog(@"%d", foo()); // logs "9"