hattenn
hattenn

Reputation: 4399

Where exactly does the "description" method get overriden?

The description method is a class method of the NSObject class. I guess it's a class method, because NSObject cannot be initialized.

When I do this:

NSLog(@"%@", [NSObject description]);

It prints out:

NSObject

But when I create a class that directly inherits from NSObject, and do this:

MyNewClass *obj = [[MyNewClass alloc] init];
NSLog(@"%@", obj);

This prints out something like:

<MyNewClass: 0x4b234a0>

I didn't specifically override the description method, how did it get overriden by my new class?

Upvotes: 1

Views: 22

Answers (1)

Abhinav
Abhinav

Reputation: 38162

That is because NSObject has two methods:

+ (NSString *)description; // Class method 
- (NSString *)description; // Instance method 

Former is defined in NSObject class and later one in in NSObject Protocol.

Upvotes: 1

Related Questions