You seem to be mostly confused about the difference between class and instance methods.
NSObject declares a class method +[NSObject description] , which, since the docs tell you: "Returns a string that represents the contents of the receiving class." If you send a description message to a class object, for example:
[NSArray description]; [NSNumber description]; [[someObject class] description];
this method will be called, and you will get a string that the class uses to describe itself.
On the other hand, the NSObject protocol declares the required instance method -[id<NSObject> description] , which will return a string describing the contents of the receiver. When you send this to an instance, you get a string representing it:
NSNumber * n = [NSNumber numberWithInt:10]; [n description]; NSArray * arr = [NSArray arrayWithObjects:@"Lemon", @"curry", @"?", nil]; [arr description]; NSDicitonary * d = [NSDictionary dictionaryWithObject:arr forKey:n]; [d description];
All NSObject subclasses inherit both of these methods, and they can be overridden, like any other. Note, for example, that NSDictionary and NSArray themselves format and send description to the objects that they contain.
It should also be noted that when using NSLog() the %@ format specifier calls description to send it to the argument (whether it be a class object or an instance).
source share