Re: respondsToSelector - #import OR compiler warnings?
Re: respondsToSelector - #import OR compiler warnings?
- Subject: Re: respondsToSelector - #import OR compiler warnings?
- From: Steve Cronin <email@hidden>
- Date: Tue, 30 Dec 2008 01:22:59 -0600
Ken;
I think I get it now. In the simple case you describe below, use:
someThing = [myObject performSelector:@selector(myMethod)] instead
of someThing = [myObject myMethod]
This seems quite useful!! performSelector's more ambitious cousins
seem a tad less 'friendly' but I get the point!
As always with you -> Quite Helpful!
Thanks,
Steve
On Dec 30, 2008, at 1:00 AM, Ken Thomases wrote:
On Dec 30, 2008, at 12:06 AM, Steve Cronin wrote:
Ken - I don't understand what you said about the method's
signature's compliance with NSObject _protocol_.
I looked at the protocol definition in the documentation and I just
don't understand well enough to see what I could do to "side-step"
the warnings,
Would you be willing to spend another sentence or two on that?
Sure. Sorry if I was unclear.
First, I only underlined "protocol" to make sure you looked in the
right place in the documentation. The -performSelector:... methods
are documented as part of the NSObject protocol, not the NSObject
class.
Second, the documentation for the -performSelector: method says the
following:
The aSelector argument should identify a method that takes no
arguments. For methods that return anything other than an object,
useNSInvocation.
That's saying that the selector you pass to -performSelector: should
be for a method which takes no arguments and returns an object
pointer. This -- the number and types of arguments and return type
-- is the "signature" of the method.
The -performSelector:withObject: and -
performSelector:withObject:withObject: methods similarly describe
the signature requirements for the method identified by the selector
you pass.
So, if you are working with a selector for a method which matches
the signature required by one of those methods, then you can safely
use those methods. Doing so is a way to invoke the method without
getting the compiler warning that was troubling you.
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden