How to write proper description method to a class?
I have implemented
- (NSString *)description {
NSString *descriptionString = [NSString stringWithFormat:@"Name: %@ \n Address: %@ \n", self.name, self.address];
return descriptionString;
}
Evrey thing is fine if I call description on my object. But if I have an array of objects and I call description on it I get:
“Name: Alex \n Address: some address \n”,
What I would like to get is
“Name: Alex
Address: some address”
I dig a little more in iOS frameworks and I have observed that the default behavior of the iOS sdk description is not to place “\n” but “;”.
Example:
The out put is:
So I have decided to use the same approach with my class.
And the out put will be:
For object it self.
For an array of objects.