Re: Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
Re: Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
- Subject: Re: Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
- From: "Dennis C. De Mars" <email@hidden>
- Date: Wed, 25 Jul 2001 20:36:52 -0000
"David P. Henderson" <email@hidden> said:
>
On Wednesday, July 25, 2001, at 01:58 , Dennis C. De Mars wrote:
>
>
> The @selector is a compiler directive (described in the Obj-C manual)
>
> that takes the
>
> name of the selector as an argument and returns a value of type SEL
>
> which is the
>
> internal Objective C representation of the selector. You always have to
>
> use it when you
>
> are passing selectors as arguments.
>
>
>
The last line of this statement is not completely true; you can also do
>
the following:
>
>
SEL aSel = @selector(doSomething); // Uses the @selector directive
Well, what I meant was that you need @selector to get at the actual selector value, so
this line doesn't really contradict what I was saying in any substantive way (I hope it
was obvious that you could store the value in a variable).
>
SEL anotherSel = NSSelectorFromString(@"doSomethingElse"); // Makes a
>
selector from a string
OK, that line _does_ contradict what I was saying in a substantive way. I guess I
wasn't thinking. This capability is extremely important for the way the entire Cocoa
system works. @selector only gives you the selector when you know the name of the
selector at compile time, but NSSelectorFromString lets you find out the selector when
you don't know the name until runtime, is the sort of thing that is needed to make it
possible to interpret the information encoded in nib files, for example.
- Dennis D.