<分区>
我有以下方法:
- (NSString *)description {
return [NSString stringWithFormat:@"Attribute %@: %@", name, [values description]];
}
Name 是一个字符串,values 是一个 NSArray。我有一个包含其中几个对象的 NSArray。
当我使用 NSLog(@"Attribute created: %@", [newAttribute description]);
打印属性时,它工作正常,并打印如下:
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
)
但是,如果我创建一个 NSMutableArray 并在其中放置几个属性对象,当我以相同的方式打印数组时,我会得到这个输出:
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)",
)
为什么它会在此上下文中打印换行符,我该如何防止它这样做?