Κυριακή, 18 Μαρτίου 2012

Description method (NSObject)

a useful method of NSObject that you can override is the Description.

if you call something like this
NSLog (@“description %@“, self);

the self will call the Description that return a NSString.

You can override the (NSString * ) description with yours messages.
Useful for NSLog debugging

Also if you try to NSLog an NSMutableArray they will show up the description of each object, that has inside here!!!


NSMutableArray *employees = [[NSMutableArray alloc] init];
…//fill the employees with objects


NSLog(@"Employees: %@", employees);

The results will be something like  that
2012-03-18 13:20:44.411 BMITime[13884:707] Employees: (
    "<Employee 0: $0 in assets>",
    "<Employee 1: $153 in assets>",
    "<Employee 2: $119 in assets>",
    "<Employee 3: $68 in assets>",
    "<Employee 4: $0 in assets>",
    "<Employee 5: $136 in assets>",
    "<Employee 6: $119 in assets>",
    "<Employee 7: $34 in assets>",
    "<Employee 8: $0 in assets>",
    "<Employee 9: $136 in assets>"
)

For clarification: the "<Employee 0: $0 in assets>” is the Description of the object that is inside the MutableArray.



Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου