OBJ-C - Getting a class name from a class hierarchy

Posted by mmmilo on Stack Overflow See other posts from Stack Overflow or by mmmilo
Published on 2010-06-08T23:05:51Z Indexed on 2010/06/08 23:12 UTC
Read the original article Hit count: 148

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa