FROM : Peter Ammon
DATE : Wed Jan 30 22:36:09 2008
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
DATE : Wed Jan 30 22:36:09 2008
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
| Related mails | Author | Date |
|---|---|---|
| Francisco Tolmasky | Jan 30, 22:14 | |
| Peter Ammon | Jan 30, 22:36 | |
| Quincey Morris | Jan 30, 22:53 |






Cocoa mail archive

