Please explain a line of code


@synthesize label, reSaleValue
-(NSString *) description


I must be dense but I just don’t understand the -(NSString *) description line. Can someone please help clear the fog.


If only the line -(NSString *) description above is confusing you, it is just part of the syntax for defining a method in Objective-C:
MethodDefinition := MethodTypeSpec ReturnTypeSpec MethodSignature MethodBody

MethodTypeSpec is ‘[color=#FF0000]+[/color]’ for class methods, and ‘[color=#FF0000]-[/color]’ for instance methods.
Thus [color=#FF0000]-[/color](NSString *) description is an instance method.

ReturnTypeSpec is further defined as b[/b], and specifies the type of the value that the method returns.
Thus -([color=#FF0000]NSString *[/color]) description is an instance method returning an NSString object (our pointer to an NSString.)

MethodSignature specifies the name of the method: just a name or a list of names and types of the parameters it takes.
Thus -([color=#FF0000]NSString *[/color]) description is method that does not take any parameters and its name is description.

If you are still feeling you are in a dense fog, the following berief description should help to clear the fog.

In Objective-C, every standard class inherits from NSObject, sitting at the top of the inheritance hierarchy.

Therefore, all classes inherit the capabilities (methods) provided by NSObject. One of those is the method -(NSString *)description.

This method is tasked with providing a human-readable description of the object instance on which it is invoked. Thus if a class feels that it should provide a better description than the one provided by NSObject, it can override the description method and provide the description it prefers.


Much better. Thanks ibex10