41

What does the caret in objective C mean?

ie.

void (^handler)(NSInteger);

from Mac Dev Center

Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
Casebash
  • 114,675
  • 90
  • 247
  • 350

3 Answers3

36

It depends on the context. In the example you show, it's used to denote a Block. The caret symbol is also the bitwise XOR operator in C-based languages — that's what most programmers would identify it as, so it's good to understand that it can be both depending on where it appears, much like *, etc.

And while we're suggesting references, one simply has to include Apple's official Blocks reference.

tresf
  • 7,103
  • 6
  • 40
  • 101
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
15

The caret represents a block or a closure which carries around or contains the lexical scope. They are similar to blocks in ruby. An excellent reference can be found here.

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
4

Like ennuikiller said, it indicates a block. If you want to learn more, Ars Technica had an excellent in-depth review of Snow Leopard that described not only blocks and closures, but also Grand Central Dispatch and all the other new technologies in Mac OS X 10.6. Highly recommended.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128