> I learned Objective-C after 3 years of (nearly) exclusive use of
> Smalltalk. I was pleased to get the added speed of C's primitive types
> (int, float, etc) and loops, but really missed blocks. A very simple use
> of a block is to apply a operation to all elements of a collection
(array),
> for example:
>
> - (void) arrayDo: (NSArray *) array
> {
> [ array do: [ :item | item doSomething ]];
> }
>
> This example can currently be coded in Objective-C, but isn't nearly as
> elegant:
>
> - (void) arrayDo: (NSArray *) array
> {
> int i;
> for (i = 0; i < [ array length ]; i += 1 )
> {
> NSObject *item = [ array objectAtIndex: i ];
> [ item doSomething ];
> }
> }
>
I personally like
[array makeObjectPerformSelector:@selector(doSomething)];