Re: SELs in arrays
Re: SELs in arrays
- Subject: Re: SELs in arrays
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 25 Sep 2001 11:45:20 -0700
On Tuesday, September 25, 2001, at 11:05 AM, Ondra Cada wrote:
John,
John C. Randolph (JCR) wrote at Tue, 25 Sep 2001 10:04:54 -0700:
JCR> >possible? Can a SEL pretend to be something else? Can anyone
think of
JCR> >another way?
JCR>
JCR> Don't store selectors, store strings:
JCR>
JCR> SEL NSSelectorFromString(NSString *aSelectorName)
JCR> NSString *NSStringFromSelector(SEL aSelector)
Agreed that it's the most flexible way, but also the most inefficient
one. I
would store them in numbers:
[array addObject:[NSNumber numberWithInt:@selector(whatever)]];
...
[anObject performSelector:[[array objectAtIndex:n] intValue] ...]
I guess it would be cleaner using NSValue, but I'm just used to the
integers ;)))
This won't work, since on Mac OS X and NEXTSTEP, selectors aren't
integers, but uniqued C strings:
(gdb) p (SEL) NSSelectorFromString(@"init")
$1 = 0x706e2644
(gdb) p (char *) $1
$2 = 0x706e2644 "init\000"...
NSStringFromSelector() is probably just a call to [NSString
stringWithCString:], or the CFString equivalent.
-jcr
"I fear all we have done is to awaken a sleeping giant and fill him with
a terrible resolve." -Admiral Isoroku Yamamoto, Dec 7, 1941.