Just like UIButton where I can:
[button addTarget:target forSelector:@selector(action)]
Or:
[button addTarget:target forSelector:@selector(action:)]
Where in the second one the action for the button will have a sender (being the button itself), how do I determine if a given selector has parameter, so that I can pass something to it?
Jeffery is right (and lots of dynamic ObjC is handled by messing with selectors this way rather than diving into the guts of
NSMethodSignature, which gives you much more precise information). But equally, you can always pass something. I know that sounds crazy, but passing too many things is not actually a problem in ObjC.Works fine. What!?!? Yeah. This is actually how your button example works. Put a breakpoint in your
IBActionand go look at the caller:It always calls
performSelector:withObject:withObject:and passes you the sender and the event even if you didn't ask for them. Try looking at$rdx(arg2) and$rcx(arg3) if you don't believe me (assuming you're in the Simulator. If you want all the right registers, you'll want the list). From my(IBAction)doThingmethod:So yes, you can tear apart the selector and figure out what to send or not send, but the typical way to do this in Cocoa is just set things up so you can always send everything and let the receiver ignore it.