Re: SELs in arrays
Re: SELs in arrays
- Subject: Re: SELs in arrays
- From: Greg Titus <email@hidden>
- Date: Tue, 25 Sep 2001 13:06:46 -0700
On Tuesday, September 25, 2001, at 12:04 PM, Ondra Cada wrote:
>
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 ;)))
And then in response to John:
>
This *will* work, since in any ObjC implementation selectors are
>
convertible
>
to int. In NeXT (and therefore Apple) ObjC they are just pointers --
>
which
>
is a type convertible to int all right.
Using +numberWithInt: and -intValue will work, but it seems to me like
it'd be better style, more readable, doesn't have to be revisited if we
ever go to 64-bit pointers, et cetera, if you write this instead:
[array addObject:[NSValue valueWithPointer:@selector(whatever)]];
...
[anObject performSelector:[[array objectAtIndex:n] pointerValue]];
-- Greg