views:

89

answers:

2

Let's say I have the following headers:

@interface SuperClass  : NSObject

@interface SubClass : SuperClass

I'm alloc'ing an instance of the class by doing:

 SubClass *sc = [[SubClass alloc] init];

In my SuperClass.m:

- (id) init
{
 self = [super init];
 if (self != nil)
 {
   NSString *cString = NSStringFromClass([self class]);
 }
 return self;
}

Simple, right? My question is: how can I get cString to return the SuperClass class, rather than the SubClass class? Since the SubClass is alloc'd/init'd, is this not possible?

Thanks!

+1  A: 

If you always want the same string to come out, why not just:

NSString *cString = @"SuperClass";
Carl Norum
I may end up resorting to this, but SubClass may be further subclassed (ie. SubSubClass). If possible I would rather not have each subclass have to hard-code this if I can use `[self class]` for each super class.
mmilo
+1  A: 
dreamlax