newbie: send message to class not instance
newbie: send message to class not instance
- Subject: newbie: send message to class not instance
- From: Horst Jäger <email@hidden>
- Date: Thu, 16 Oct 2008 18:38:58 +0200
Hi,
let's say I have a class "MyClass"
@interface MyClass : NSObject{
- (void) myInstanceMethod;
+ (void) myClassMethod;
}
with an instance "myInstance"
MyClass *myInstance = [[MyClass alloc] init];
. I could then call myInstanceMethod like
[myInstance myInstanceMethod];
. I could call the static (or, like the Java-people say, class-) method like
[MyClass myClassMethod];
. I couldn't, however, call the static method via the Instance:
[myInstance myClassMethod];
wouldn't work. That's different in the languages I know, e.g. Java .
So far the preliminaries. Here comes the problem:
I could send a message to the instance, calling the instance-method
with objc_msgSend or one of the related commands like "performSelector":
objc_msgSend(myInstance, @selector(myInstanceMethod));
But I can't send a message to the instance, calling the static
method with objc_msgSend :
objc_msgSend(myInstance, @selector(myClassMethod));
, because that's the same as
[myInstance myClassMethod];
which doesn't work as said above.
But I can't send a message to the class either, calling the static
method with objc_msgSend:
objc_msgSend(MyClass , @selector(myClassMethod));
because MyClass is not a term for an Object, so I get a syntax error.
Thus there seems to be no way to call a static method by sending a
message via objc_msgSend .
Is that so? Any help?
Thanks in advance
Horst
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden