On 19/04/2010, at 10:14 AM, Dave DeLong wrote:

> If I'm inside a method, is there a way to know at runtime whether that method 
> is a class or an instance method?  Currently the only way I though of to do 
> this is to see if "self" is a Class object or not, but I was wondering if 
> there's a more reliable way to determine this.


I might be lacking imagination here, but I can't think of any situation where 
needing to detect this would make any sense. Methods should be written with 
this knowledge built-in to them, since they can either function as class 
methods or instance methods but not both. And client code should also know what 
it's doing and will call the appropriate method for whatever task it wants the 
object to carry out.

You could ask whether [[self class] instancesRespondToSelector:_cmd] and if it 
returns YES it's an instance method. But I'm boggling trying to think of a 
legitimate use case.

--Graham


_______________________________________________

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

Reply via email to