/ Published in: Objective C

Examples of how Objective-c objects work
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//-----demonstrate how blocks hold their captured state void (^now)(void) = ^ { NSLog(@"The date and time is %@", date); }; now(); sleep(5); now(); //-------------- int (^triple)(int) = ^(int number) { return number * 3; }; int result1 = triple(2); int (^multiply)(int, int) = ^(int x, int y) { return x * y; }; int result2 = multiply(2, 3); NSLog(@"result %i", result2); result2 = multiply(5, 3); NSLog(@"result %i", result2);
Comments
