discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: little question about class versioning


From: Wolfgang Lux
Subject: Re: little question about class versioning
Date: Thu, 13 Sep 2012 13:28:36 +0200

Hi Sebastian,

> which gives me the following output:
> 
> 2012-09-13 11:47:30.072 TestTool[27335] SuperClass class_getVersion([super 
> class]): 8
> 2012-09-13 11:47:30.081 TestTool[27335] SuperClass class_getVersion([MyClass 
> class]): 1
> 2012-09-13 11:47:30.081 TestTool[27335] SuperClass [[super class] version]: 8
> 2012-09-13 11:47:30.081 TestTool[27335] SubClass class_getVersion([self 
> class]): 8
> 2012-09-13 11:47:30.081 TestTool[27335] SubClass class_getVersion([MySubClass 
> class]): 8
> 2012-09-13 11:47:30.081 TestTool[27335] SubClass [[self class] version]: 8
> 
> What I wonder is why line 1 and line 3 returns 8 instead of 1.
> I guess there must be a simple solution, but I was looking into NSObject.m 
> but did not found
> yet, why I only get the 1 in the 2nd line.
> 
> If somebody could explain that, or has a pointer to documentation where to 
> read up,
> that would be helpful.

I guess you wonder because you misunderstood what [super class] does.
This method call invokes the class method on the super class of the receiver, 
i.e., on the super class of SubClass. However, the class method is implemented 
in NSObject, which itself is a super class of SuperClass. So calling [super 
class] is just the same as calling [self class] and will return the class of 
the receiver (and not the receiver's super class as you seem to expect).

Wolfgang




reply via email to

[Prev in Thread] Current Thread [Next in Thread]