Question
Does objective-c have any kind of functionality which allows me to compose my own blocks or IMP
s on the fly?
By that I mean let me link together arbitrary code snippets into a single block (and then perform imp_implementationWithBlock
) or just get an assembled IMP
straight up.
Pseudocode
(IMP) linkExistingBlock:LBExistingBlock With:^{
}
or
(IMP) linkExistingBlock:LBExistingBlock With:LBAnotherBlock
If you have two Blocks, just call them. Further, Blocks are objects, and can be put into
NSArray
s. Then you can enumerate the array and invoke its contents.or
If you have
IMP
s, those are just function pointers -- they can be put into a C array, or wrapped inNSValue
s and put into a Cocoa array. You just need to cast them before you try to call them.For your example method signature: