discuss-gnustep
[Top][All Lists]
Advanced

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

little question about class versioning


From: Sebastian Reitenbach
Subject: little question about class versioning
Date: Thu, 13 Sep 2012 11:52:59 +0200
User-agent: SOGoMail 1.3.18

Hi,

I have the following test program:

#import <Foundation/Foundation.h>

@interface MyClass: NSObject
@end

@interface MySubClass: MyClass
@end

@implementation MyClass
+(void)initialize
{
  [self setVersion: 1];
}
@end

@implementation MySubClass
+(void)initialize
{
  [self setVersion: 8];
}

-(id) init
{
  self = [super init];
  NSLog(@"SuperClass class_getVersion([super class]): %i", 
class_getVersion([super class]));
  NSLog(@"SuperClass class_getVersion([MyClass class]): %i", 
class_getVersion([MyClass class]));
  NSLog(@"SuperClass [[super class] version]: %i", [[super class] version]);
  NSLog(@"SubClass class_getVersion([self class]): %i", class_getVersion([self 
class]));
  NSLog(@"SubClass class_getVersion([MySubClass class]): %i", 
class_getVersion([MySubClass class]));
  NSLog(@"SubClass [[self class] version]: %i", [[self class] version]);
  return self;
}
@end


int
main(int argc, const char *argv[])
{
  id pool = [[NSAutoreleasePool alloc] init];

  MySubClass *my = [[MySubClass alloc] init];
  
  
  [pool release];

  return 0;
}

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.

thanks,
Sebastian



reply via email to

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