Thursday, August 28, 2008

Blocks in Objective-C

Apple is adding blocks (a.k.a. closures) to Objective-C (via Ian Baird):

From a technical perspective, blocks fit into C in a couple places: 1) a new declaration type (the caret) which work very much like a magic kind of pointer that can only point to function types. 2) block literals, which capture the computation 3) a new storage class __block 4) a really tiny runtime library.

The new storage class comes into play when you want to get mutable access to variables on the stack. Basically you can mark an otherwise- auto variable with __block…

Update (2008-08-30): Jens Alfke comments.

1 Comment RSS · Twitter

[...] and a variable number of arguments, and it performs the selector on each object in the array. Blocks are much nicer, of course, but they’re not available yet in Objective-C. Higher order [...]

Leave a Comment