I have the following method:
- (NSString *)description {
return [NSString stringWithFormat:@"Attribute %@: %@", name, [values description]];
}
Name is a string, values is an NSArray. I have an NSArray containing several of these objects.
When I print the attribute using NSLog(@"Attribute created: %@", [newAttribute description]);
it works fine, and prints this:
2012-12-08 14:38:06.883 DT[25684:303] Attribute created: Attribute color: (
YELLOW,
PURPLE
)
2012-12-08 14:38:06.884 DT[25684:303] Attribute created: Attribute size: (
LARGE,
SMALL
)
However, if I create a NSMutableArray and place several attribute objects in it, I get this output when I print the array in the same manner:
2012-12-08 14:38:06.887 DT[25684:303] Attributes: (
"Attribute color: (\n YELLOW,\n PURPLE\n)",
"Attribute size: (\n LARGE,\n SMALL\n)",
)
Why does it print the newline character in this context, and how would I prevent it from doing so?
It looks like this question was answered here: https://stackoverflow.com/a/5599699/5760384
Basically, like Exploring said, the \n character doesn't work in the description, but for some reason a carriage return does. So try \r instead. I tested this out in an overridden description method in Xcode 7 and it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With