Created
May 25, 2012 08:27
-
-
Save 1901/2786627 to your computer and use it in GitHub Desktop.
Objective-C中block的使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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