Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caret in objective C

What does the caret in objective C mean?

ie.

void (^handler)(NSInteger);

from Mac Dev Center

like image 202
Casebash Avatar asked Dec 16 '09 03:12

Casebash


People also ask

What does caret mean in Swift?

The caret symbol creates a block, which is similar to a delegate. It's a type of closure—a function defined inline that also has access to variables in the parent scope, which can often be used to greatly simplify certain types of delegate-/callback-oriented code.


3 Answers

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.

like image 179
Quinn Taylor Avatar answered Sep 29 '22 16:09

Quinn Taylor


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.

like image 44
ennuikiller Avatar answered Sep 29 '22 15:09

ennuikiller


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.

like image 41
Shaggy Frog Avatar answered Sep 29 '22 15:09

Shaggy Frog