I want to declare a block type that takes one parameter, which is the same block type. This is something like this:
typedef void (^BlockInBlock) (BlockInBlock block);
I know the ad is not valid. But I am wondering if there is any possible way to implement a recursive block that takes only one parameter, which is the same type of block.
I am trying to find a way to implement aspect-oriented programming (AOP) in Objective-C using a block. Here are my questions on how to implement this.
Further question 1:
How to implement a variational function that takes up many blocks described above and ends with nil , and I could call this function with many blocks until I encounter zero? It will be like this:
@interface NSObject(AOP) - (void) invokeBlockInBlock:(BlockInBlock) headBlock, ...{ va_list blockList; va_start(blockList, headBlock); // Invoke recursive blocks here until the value of va_arg(blockList, BlockInBlock) is nil // it would be like: block1(self, block2(self, block3(self, block4(...)))); va_end(blockList); } @end
Further question 2:
What if the recursive block has a return value?
Additional C language question:
Is it possible to declare a function C that takes one parameter, which is a pointer to the function C, and that the pointer function of the function C also takes another pointer to the function C?
objective-c aop block recursion
李 岡 諭
source share