^符号在Objective-C中意味着什么?

时间:2012-07-02 06:25:47

标签: objective-c ios objective-c-blocks

  

可能重复:
  Caret in objective C

^符号在Objective-C中意味着什么?

代码:

 GreeRequestServicePopup* requestPopup = [GreeRequestServicePopup popup];
 requestPopup.parameters = parameters;

 requestPopup.willLaunchBlock = ^(id aSender) {
 [[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_will_launch_block" object:nil];

 };

 requestPopup.didLaunchBlock = ^(id aSender) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_did_launch_block" object:nil];
 };

 requestPopup.willDismissBlock = ^(id aSender) {
 [[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_will_dismiss_block" object:nil];
 };

 requestPopup.didDismissBlock = ^(id aSender) {
 [[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_did_dismiss_block" object:nil];
 };

 requestPopup.cancelBlock = ^(id aSender) {
 [[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_cancel_block" object:nil];
 };

 requestPopup.completeBlock = ^(id aSender) {
 [[NSNotificationCenter defaultCenter] postNotificationName:@"request_service_popup_complete_block" object:nil];
 };

 [self.navigationController showGreePopup:requestPopup];
 }

提前致谢!

3 个答案:

答案 0 :(得分:5)

^是一个block字面值。块文字后跟参数,然后是花括号以表示代码的实际内容:

| ^          | (id arg)    | {};          |
|:-----------|------------:|:------------:|
| Block      | Parameters  |     Body     |
| literal    |             |              |

块文字的解释相当清楚here

答案 1 :(得分:3)

^表示阻止。点击此处:http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html

实际上,这指定了将在稍后执行的一段代码。

答案 2 :(得分:1)

那些是块。你可以阅读一篇很好的介绍here。然后阅读Blocks Programming Topics了解更多详情。