I'm not at my machine at the moment, so please excuse any errors in my
example code below. I'm trying to get some runtime object/selector
calling to work, and running into a very weird problem. Do***entation
online (even on Apple's website) is pretty sparse on the subject, and
I'm hoping someone here can give me a good example or tell me where
I'm screwing up. :-)
I have two strings at runtime: the class and method name. Given the
do***entation I've read so far, my understanding is that I should be
able to do this:
void send_class_msg(const char* cls_name, const char* mthd_name)
{
Class c = objc_getClass(name);
SEL s = sel_registerName(mthd_name);
[c performSelector: s];
// or... objc_msgSend(c, s, ...);
}
That's a pretty trivial example, but generally gets the idea across.
The class value returned is just fine. If I replace #performSelector:
with #alloc, I get a new instance of the class and the universe is
right.
However, for some reason the selector is somehow _not_ right. I've
changed a lot of the code significantly, trying lots of other ideas to
compare the results. For example:
SEL s_good = @[EMAIL PROTECTED]
(alloc);
SEL s_bad = sel_registerName("alloc");
assert(s_good == s_bad); // this asserts true!!
[c performSelector: s_good]; // this works!
[c performSelector: s_bad]; // this does not work!
This is driving me nuts as I can't figure out what the hell is wrong.
My only guess is that @[EMAIL PROTECTED]
is doing a little more at compile-time
than sel_registerName() is doing at runtime. But that's just a wild
guess.
In anticipation of what's coming next, I'm also going to need to send
runtime argument lists that aren't known at compile time. So,
objc_msgSend() won't fit my needs (the ... argument list won't cut
it). On the web it looks like there's a objc_msgSendv() function that
will probably work, but I can't tell if this is sup****ted by Apple or
is only special function for some Objective-C compilers? And I can't
find any do***entation for it. Does anyone have a link to a good
example of this in use?
Thanks in advance!
Jeff M.


|