我想查看我的字典在控制檯日誌中的對象類。至於標準NSObject
子類,我在類別覆蓋-(NSString*) description
:NSDictionary的細化描述
-(NSString*) description
{
NSMutableString* desc = [NSMutableString stringWithFormat: @"<%@ 0x%08x>\nobjects count: %ld", [self class], (uint)self, [self count]];
for (id key in [self allKeys])
[desc appendFormat: @"\n%@ = %@ (%@)", key, [self objectForKey: key], [[self objectForKey: key] class]];
return desc;
}
它的工作原理,但僅用於頂級NSDictionary
對象(如果該對象在兒童字典他們登錄繞過description
方法)。因此,NSDictionary
以某種方式打印其子對象,而不會在其上調用description
...
是否有方法通過我的description
方法記錄這些兒童字典?
PS:在實際情況下,我想在字典中找到一個無法保存到plist
的對象。也許還有另一種解決方案,我也會爲此感謝。
你可以嘗試明確調用'description'嗎? – trojanfoe
你的意思是遍歷字典嗎?迭代會很困難,因爲字典足夠複雜,其中一個孩子是不正確的。 – brigadir
我認爲@trojanfoe建議用'[[self objectForKey:key] description]' – Felix