objective c - Caret character between types rather than variables, surrounded by parentheses -


i going through apple's documentation , saw (void (^)(void)). can explain statement means? ^ xor, right? void xor void doesn't makes sense me?

there (void (^)(bool finished))

these blocks add anonymous functions , function objects objective-c. see e.g. introducing blocks , grand central dispatch :

block objects (informally, “blocks”) extension c, objective-c , c++, make easy programmers define self-contained units of work. blocks similar — far more powerful — traditional function pointers. key differences are:

  • blocks can defined inline, “anonymous functions.”
  • blocks capture read-only copies of local variables, similar “closures” in other languages

declaring block variable:

void (^my_block)(void); 

assigning block object it:

my_block = ^(void){ printf("hello world\n"); }; 

invoking it:

my_block(); // prints “hello world\n” 

accepting block argument:

- (void)dosomething:(void (^)(void))block; 

using method inline block:

[obj dosomething:^(void){ printf("block called"); }];