• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: SELs in arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: SELs in arrays
      • From: Ondra Cada <email@hidden>
References: 
 >Re: SELs in arrays (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: SELs in arrays
  • Next by Date: Re: SELs in arrays
  • Previous by thread: Re: SELs in arrays
  • Next by thread: Re: SELs in arrays
  • Index(es):
    • Date
    • Thread