I'm writing a class where you register an object and a property to observe. When the property gets set to something non-nil
, a registered callback selector is called (like target-action). The selector may have three different signatures, and the right one is called depending on which type was registered.
This works fine, but now I want to add the ability to register a Block instead of a selector as the "callback function". Is it possible to find out the function signature of the supplied Block and handle the callback differently depending on the type of Block supplied?
For example:
- (void)registerCallbackBlock:(id)block
{
if ([self isBlock:block] {
if ([self isMethodSignatureOne:block]) { /* */ }
else if ([self isMethodSignatureTwo:block]) { /* */ }
else { assert(false); } // bad Block signature
block_ = block; // assuming ARC code
}
else { assert(false); } // not a block
}
- (void)callBlock
{
if ([self isMethodSignatureOne:block_] {
block_(arg1_, arg2_); // needs casting?
}
else if ([self isMethodSignatureTwo:block_) {
block_(arg1_, arg2_, arg3_); // needs casting?
}
}
Any ideas?
I know I can make different register functions with specific typedef
'ed Block arguments but I would rather have a single function, if possible.