Skip to content

Instantly share code, notes, and snippets.

@1901
Created May 25, 2012 08:27
Show Gist options
  • Save 1901/2786627 to your computer and use it in GitHub Desktop.
Save 1901/2786627 to your computer and use it in GitHub Desktop.
Objective-C中block的使用
int i = 5;
int (^test1)() = ^() {
return i * i;
};
int (^test2)(int);
test2 = ^(int a) {
return a * a;
};
NSString* str = ^(NSString* aStr){
return aStr;
}(@"hello");
NSLog(@"test1===>%d", test1());
NSLog(@"test2===>%d", test2(3));
NSLog(@"str===>%@", str);
NSLog(@"===== END =====");
// ================= 輸出結果 ===================
2012-05-25 16:25:03.544 fs_test[62360:b603] test1===>25
2012-05-25 16:25:03.545 fs_test[62360:b603] test2===>9
2012-05-25 16:25:03.546 fs_test[62360:b603] str===>hello
2012-05-25 16:27:27.395 fs_test[62360:b603] ===== END =====
// =============================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment