Re: Class introspection [was Re: Forcing allocation of a subclass]
Re: Class introspection [was Re: Forcing allocation of a subclass]
- Subject: Re: Class introspection [was Re: Forcing allocation of a subclass]
- From: João Varela <email@hidden>
- Date: Sun, 25 Jan 2009 20:27:01 +0000
No, isKindOfClass check for the superclass. It returns true if self
class is myClass or a subclass of myClass.
You should use isMemberOfClass: to got something equivalent.
Yes, you are right. Thanks for pointing it out.
because in the first example we are calling -class: in [self class]
and on the right we are calling +class: in [MyClass class]. This
actually surprises me. Even though the +class: method is a NSObject
class method and -class: is part of the NSObject protocol. How is
that possible there is no collision between these two methods.
Isn't that a case of overloading???
It's perfectly legal to have class methods and instance methods with
the same name.
But there is more:
Methods of the Root Class
All objects, classes and instances alike, need an interface to the
runtime system. Both class objects and instances should be able to
introspect about their abilities and to report their place in the
inheritance hierarchy. It’s the province of the NSObject class to
provide this interface.
So that NSObject's methods don’t have to be implemented twice—once
to provide a runtime interface for instances and again to duplicate
that interface for class objects—class objects are given special
dispensation to perform instance methods defined in the root class.
When a class object receives a message that it can’t respond to with
a class method, the runtime system determines whether there’s a root
instance method that can respond. The only instance methods that a
class object can perform are those defined in the root class, and
only if there’s no class method that can do the job.
For more on this peculiar ability of class objects to perform root
instance methods, see the NSObject class specification in the
Foundation framework reference
I think read it once but that was long ago and didn't pay attention to
is as much. Learning about Obj-C and Cocoa every day.
Thanks for answering.
JV_______________________________________________
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