I'm working on a class that involves sending a selector as a variable to be used later. The selector is required to take one argument, a BOOL value. Executed like so:
IMP imp = [ob methodForSelector:selector];
void (*func)(id, SEL, BOOL) = (void *)imp;
func(ob, selector, YES);
If someone tries to set a selector with a variable that doesn't match a BOOL, I'd like to return an error. Is there a way, when receiving the selector that I can check whether or not its argument is a BOOL, or in general, what Class or Type of argument has been passed?
Why?
I'm setting up a quasi notification center in one of my classes so I can easily add observers and have more control over information distribution.
Look at the method signature:
NSMethodSignature * sig = [ob methodSignatureForSelector:selector];
NSAssert(0 == strcmp(@encode(BOOL), [sig getArgumentTypeAtIndex:2]),
@"Method must take a BOOL as its sole argument.");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With