Description to return only ClassName?

The default description for the class instance returns "ClassName: 0x105120". How do I change the method below to just return "ClassName"?

// The code below just returns the address ... - (NSString *)description { NSString *result; result = [NSString stringWithFormat:@"%p", self]; return result; } 

EDIT: in this case will it be correct? Although I understand that if I want to get the class name as NSString, I have to use NSStringFromClass ([self class])

 - (id)init { NSLog(@"_init: %@", [self class]); [super init]; return self; } 

thanks in advance -gary -

+7
objective-c nsstring
source share
1 answer

iPhoneOS: NSStringFromClass([self class])
MacOS: [self className]

... gives you an NSString with a class name

Edit:

For iPhoneOS and MacOS way:

NSStringFromClass([self class])

+20
source share

All Articles