• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How Do Classes Respond to performSelector?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How Do Classes Respond to performSelector? (From: Francisco Tolmasky <email@hidden>)

  • Prev by Date: Re: Best way to notify the Controller when one Array object value is changed
  • Next by Date: Re: How Do Classes Respond to performSelector?
  • Previous by thread: How Do Classes Respond to performSelector?
  • Next by thread: Re: How Do Classes Respond to performSelector?
  • Index(es):
    • Date
    • Thread