NSArray 的 -description 方法将嵌套递归调用,如下所示:
2009-05-15 14:28:09.998 TestGUIProject[29695:813] (
a, // Array1 item 1
( // Array2, a second array, nicely indented another 4 spaces
a // Item in Array2
) // End of Array2
) // End of Array1
我想为我自己的自定义类做类似的事情(使用我正在编写的脚本)。
我不知道当递归调用的对象添加自己的新行时如何添加额外的缩进级别。
我所拥有的是以下内容:
- (NSString *)description {
return [NSString stringWithFormat:@"{{{\n"
@" prop1: %@\n"
@" prop2: %@\n"
@" prop3: %@\n"
@" prop4: %@\n"
@"}}}",
self.prop1,
self.prop2,
self.prop3,
self.prop4];
}
但是,一旦其中一个属性是 NSArray 或使用相同描述格式的另一个对象,这就会崩溃,因为它不能很好地嵌套。
相反,您会得到:
2009-05-15 14:25:50.899 TestApp[29636:813] {{{
prop1: SomeValue1
prop2: ( // Prop 2 is an Array of strings
"String1", // Note no additional level of indentation as in the NSArray example
"String2",
"String3",
"String4"
)
prop3: SomeValue3
prop4: SomeValue4
}}}
如何获得额外的嵌套级别?