Re: How Do Classes Respond to performSelector?
Re: How Do Classes Respond to performSelector?
- Subject: Re: How Do Classes Respond to performSelector?
- From: Peter Ammon <email@hidden>
- Date: Wed, 30 Jan 2008 13:36:09 -0800
On Jan 30, 2008, at 1:14 PM, Francisco Tolmasky wrote:
This is just a question out of curiosity. In the developer docs,
only - (id)performSelector: is defined.
So I was going to write my own + (id)perfromSelector, but first
figured I'd check whether there was
one already by writing up a quick test in XCode - which it turns
out there is (saved me the work).
In Objective-C, a class object gets all the instance methods of the
root class for its hierarchy. This means that every class object
that descends from NSObject gets all of NSObject's instance methods -
including performSelector:.
This isn't a magic property of NSObject. Your own root classes do
this too:
#import <objc/objc.h>
@interface MyRootClass @end
@implementation MyRootClass
- (void)sayHi { puts("Hi!"); }
+ (void)initialize { /* Must be implemented */ }
@end
@interface MySubclass : MyRootClass @end
@implementation MySubclass @end
int main(void) {
[MySubclass sayHi];
return 0;
}
Calling sayHi on the class object invokes the instance method of the
root class.
Hope that's clear,
-Peter
_______________________________________________
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