Reputation: 26223
The default description for a class instance returns "ClassName: 0x105120". How might I modify the method below to just return the "ClassName"?
// The code below just returns the address ...
- (NSString *)description {
NSString *result;
result = [NSString stringWithFormat:@"%p", self];
return result;
}
EDIT: in that case would this be correct? Although I do understand that if I want to actually get the className as an NSString I should use NSStringFromClass([self class])
- (id)init {
NSLog(@"_init: %@", [self class]);
[super init];
return self;
}
thanks in advance -gary-
Upvotes: 7
Views: 3790
Reputation: 81878
iPhoneOS: NSStringFromClass([self class])
MacOS: [self className]
... gives you an NSString with the class name
Edit:
For both iPhoneOS and MacOS the way to go is:
NSStringFromClass([self class])
Upvotes: 20