Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
- Subject: Passing selectors as Arguments (Was: - (void)sortUsingSelector:(SEL)comparator )
- From: "David P. Henderson" <email@hidden>
- Date: Wed, 25 Jul 2001 15:07:16 -0400
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
SEL anotherSel = NSSelectorFromString(@"doSomethingElse"); // Makes a
selector from a string
Which allows you to pass the variables without using the @selector
directive, but using the directive is often the simplest, easiest way to
pass a method as an argument. The above are more useful if you need to
use the selector more than a few times, and I'll leave it for the
uninitiated to discover how truly useful it can be to have a function
like NSSelectorFromString().
Dave
--
Chaos Assembly Werks
"Imagination is more important than knowledge."
- Albert Einstein