Declare a block method parameter without using a typedef

Bogatyr picture Bogatyr · Mar 30, 2011 · Viewed 88.7k times · Source

Is it possible to specify a method block parameter in Objective-C without using a typedef? It must be, like function pointers, but I can't hit on the winning syntax without using an intermediate typedef:

typedef BOOL (^PredicateBlock_t)(int);
- (void) myMethodTakingPredicate:(PredicateBlock_t)predicate

only the above compiles, all these fail:

-  (void) myMethodTakingPredicate:( BOOL(^block)(int) ) predicate
-  (void) myMethodTakingPredicate:BOOL (^predicate)(int)

and I can't remember what other combinations I've tried.

Answer

Macmade picture Macmade · Mar 30, 2011
- ( void )myMethodTakingPredicate: ( BOOL ( ^ )( int ) )predicate