Re: class_respondsToSelector() in runtime.h?
On Wed, 30 Jun 2010 18:02:38 -0400, Laurent Daudelin laur...@nemesys-soft.com said: On Jun 30, 2010, at 17:48, Greg Parker wrote: On Jun 30, 2010, at 2:42 PM, Laurent Daudelin wrote: Yes, I know that, but can you send an instance method to a class object? Yes, you can. Every class object is itself an instance of NSObject. Thanks, Greg. I guess you learn something new every day Apple's own Cocoa Fundamentals Guide is well worth reading. It's truly excellent, and tells about Cocoa fundamentals (i.e. things one needs to know in order to use Cocoa): http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Cocoa Fundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-C H4-SW35 Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Wed, Jun 30, 2010 at 5:44 PM, Dave Carrigan d...@rudedog.org wrote: On Jun 30, 2010, at 2:35 PM, Laurent Daudelin wrote: Well, isn't -respondsToSelector: an instance method? if ([[Someclass class] respondsToSelector:@selector(classSelector)]) { // yup } An extremely minor nitpick: the use of +class here is necessary. You can simply write [Someclass respondsToSelector:...]. The use of [Someclass class] is only necessary when you want to use Someclass as a value or parameter or such. Mike ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
For more information: http://stackoverflow.com/questions/3107213 Dave On Jul 1, 2010, at 10:05 AM, Michael Ash wrote: On Wed, Jun 30, 2010 at 5:44 PM, Dave Carrigan d...@rudedog.org wrote: On Jun 30, 2010, at 2:35 PM, Laurent Daudelin wrote: Well, isn't -respondsToSelector: an instance method? if ([[Someclass class] respondsToSelector:@selector(classSelector)]) { // yup } An extremely minor nitpick: the use of +class here is necessary. You can simply write [Someclass respondsToSelector:...]. The use of [Someclass class] is only necessary when you want to use Someclass as a value or parameter or such. smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Thu, Jul 1, 2010 at 12:05 PM, Michael Ash michael@gmail.com wrote: An extremely minor nitpick: the use of +class here is necessary. Of course I meant to write that the use of +class here is UNnecessary. Sigh. Mike ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jul 1, 2010, at 9:14 AM, Michael Ash michael@gmail.com wrote: On Thu, Jul 1, 2010 at 12:05 PM, Michael Ash michael@gmail.com wrote: An extremely minor nitpick: the use of +class here is necessary. Of course I meant to write that the use of +class here is UNnecessary. Sigh. And it can actually get you into trouble. +class returns self, so this won't do what you might think at first: [[SomeClass class] instancesRespondToSelector:@selector(foo)] One might think that asks if the SomeClass class object responds to foo, following the logic that [SomeClass class] would return SomeClass's metaclass. In fact, as Mike describes, it is equivalent to [SomeClass instancesRespondToSelector:@selector(foo)]. --Kyle Sluder___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jul 1, 2010, at 7:56 AM, Matt Neuburg wrote: Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. Not that it would generally be USEFUL to do so, since the purpose of an instance is to hold instance variable values; a class object accessing instance variables through an instance method would come up with uninitialized ivar values, no? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jul 1, 2010, at 9:42 AM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: On Jul 1, 2010, at 7:56 AM, Matt Neuburg wrote: Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. Not that it would generally be USEFUL to do so, since the purpose of an instance is to hold instance variable values; a class object accessing instance variables through an instance method would come up with uninitialized ivar values, no? They are instances of the root class, so they have all the root class instances variables, of which there is precisely one: isa. --Kyle Sluder___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jul 1, 2010, at 9:49 AM, Kyle Sluder wrote: On Jul 1, 2010, at 9:42 AM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: On Jul 1, 2010, at 7:56 AM, Matt Neuburg wrote: Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. Not that it would generally be USEFUL to do so, since the purpose of an instance is to hold instance variable values; a class object accessing instance variables through an instance method would come up with uninitialized ivar values, no? They are instances of the root class, so they have all the root class instances variables, of which there is precisely one: isa. Interesting... so what happens at runtime if a class object invokes an instance method that accesses instance variables? Exception? Assertion? Seg fault? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
Le 1 juil. 2010 à 19:30, Jonathon Kuo a écrit : On Jul 1, 2010, at 9:49 AM, Kyle Sluder wrote: On Jul 1, 2010, at 9:42 AM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: On Jul 1, 2010, at 7:56 AM, Matt Neuburg wrote: Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. Not that it would generally be USEFUL to do so, since the purpose of an instance is to hold instance variable values; a class object accessing instance variables through an instance method would come up with uninitialized ivar values, no? They are instances of the root class, so they have all the root class instances variables, of which there is precisely one: isa. Interesting... so what happens at runtime if a class object invokes an instance method that accesses instance variables? Exception? Assertion? Seg fault? It just works. isa is a valid pointer on the expected type, even for classes. -- Jean-Daniel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Thu, Jul 1, 2010 at 1:30 PM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: On Jul 1, 2010, at 9:49 AM, Kyle Sluder wrote: On Jul 1, 2010, at 9:42 AM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: On Jul 1, 2010, at 7:56 AM, Matt Neuburg wrote: Instance methods defined in a root class can be performed both by instances and by class objects. Therefore, all class objects have access to the instance methods defined in the root class. Not that it would generally be USEFUL to do so, since the purpose of an instance is to hold instance variable values; a class object accessing instance variables through an instance method would come up with uninitialized ivar values, no? They are instances of the root class, so they have all the root class instances variables, of which there is precisely one: isa. Interesting... so what happens at runtime if a class object invokes an instance method that accesses instance variables? Exception? Assertion? Seg fault? I think you may have missed the part where only instance methods defined IN A ROOT CLASS can be performed by class objects. Therefore the scenario that you describe cannot occur. Mike ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Thu, Jul 1, 2010 at 10:30 AM, Jonathon Kuo newsli...@autonomy.caltech.edu wrote: Interesting... so what happens at runtime if a class object invokes an instance method that accesses instance variables? Exception? Assertion? Seg fault? Invoke is an inaccurate word. Let's use the proper term, send a message. The sender of the message is irrelevant; all that matters is the receiver. It sounds like you have gotten confused, and interpreted the above thread to mean that a class object will respond to its instance methods? This is not true. A class object will only respond to instance methods defined on the root class. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
class_respondsToSelector() in runtime.h?
I need to check for backward compatibility whether a given class object responds to a selector. I found the function 'class_respondsToSelector()' which the doc says is defined in 'runtime.h'. However, I can't find that header anywhere. Does anybody know where that header might be? No, it's not in /usr/include... -Laurent. -- Laurent Daudelin AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/ Logiciels Nemesys Software laur...@nemesys-soft.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
#import objc/runtime.h Dave Sent from my iPhone On Jun 30, 2010, at 1:43 PM, Laurent Daudelin laur...@nemesys-soft.com wrote: I need to check for backward compatibility whether a given class object responds to a selector. I found the function 'class_respondsToSelector()' which the doc says is defined in 'runtime.h'. However, I can't find that header anywhere. Does anybody know where that header might be? No, it's not in /usr/include... -Laurent ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 12:43 PM, Laurent Daudelin wrote: I need to check for backward compatibility whether a given class object responds to a selector. I found the function 'class_respondsToSelector()' which the doc says is defined in 'runtime.h'. Is there some reason you can't call -respondsToSelector: on the class object? -- Greg Parker gpar...@apple.com Runtime Wrangler ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 16:55, Greg Parker wrote: On Jun 30, 2010, at 12:43 PM, Laurent Daudelin wrote: I need to check for backward compatibility whether a given class object responds to a selector. I found the function 'class_respondsToSelector()' which the doc says is defined in 'runtime.h'. Is there some reason you can't call -respondsToSelector: on the class object? Well, isn't -respondsToSelector: an instance method? -Laurent. -- Laurent Daudelin AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/ Logiciels Nemesys Software laur...@nemesys-soft.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 2:35 PM, Laurent Daudelin laur...@nemesys-soft.com wrote: On Jun 30, 2010, at 16:55, Greg Parker wrote: Is there some reason you can't call -respondsToSelector: on the class object? Well, isn't -respondsToSelector: an instance method? Remember that NSObject is a root class. --Kyle Sluder___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 17:41, Kyle Sluder wrote: On Jun 30, 2010, at 2:35 PM, Laurent Daudelin laur...@nemesys-soft.com wrote: On Jun 30, 2010, at 16:55, Greg Parker wrote: Is there some reason you can't call -respondsToSelector: on the class object? Well, isn't -respondsToSelector: an instance method? Remember that NSObject is a root class. Yes, I know that, but can you send an instance method to a class object? -Laurent. -- Laurent Daudelin AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/ Logiciels Nemesys Software laur...@nemesys-soft.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 2:35 PM, Laurent Daudelin wrote: Well, isn't -respondsToSelector: an instance method? if ([[Someclass class] respondsToSelector:@selector(classSelector)]) { // yup } -- Dave Carrigan d...@rudedog.org Seattle, WA, USA ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 2:42 PM, Laurent Daudelin wrote: Yes, I know that, but can you send an instance method to a class object? Yes, you can. Every class object is itself an instance of NSObject. Therefore, every class object also responds to all of NSObject's instance methods. http://sealiesoftware.com/blog/archive/2009/04/14/objc_explain_Classes_and_metaclasses.html (Pedantically, every class object is itself an instance of its root class. But to a close approximation that root class is always NSObject.) -- Greg Parker gpar...@apple.com Runtime Wrangler ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: class_respondsToSelector() in runtime.h?
On Jun 30, 2010, at 17:48, Greg Parker wrote: On Jun 30, 2010, at 2:42 PM, Laurent Daudelin wrote: Yes, I know that, but can you send an instance method to a class object? Yes, you can. Every class object is itself an instance of NSObject. Therefore, every class object also responds to all of NSObject's instance methods. http://sealiesoftware.com/blog/archive/2009/04/14/objc_explain_Classes_and_metaclasses.html (Pedantically, every class object is itself an instance of its root class. But to a close approximation that root class is always NSObject.) Thanks, Greg. I guess you learn something new every day. I've never had to check if a class object responded to a selector before but now that's good to know! Going back to my code now... -Laurent. -- Laurent Daudelin AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/ Logiciels Nemesys Software laur...@nemesys-soft.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com