Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line character showing up in NSLog output [duplicate]

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?

like image 491
Justin Mrkva Avatar asked Dec 08 '12 19:12

Justin Mrkva


1 Answers

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.

like image 136
Nicronaide Avatar answered Oct 01 '22 22:10

Nicronaide