I have an NSDictionary. It holds several objects, including an array of child NSDictionaries, each of which have an object keyed as @"Parent" that point back to the parent NSDictionary.
This circular reference breaks the ability to inspect the object with a classic call like:
NSLog(@"%@", [myDictionary description]);
Would anyone be so kind as to recommend a workaround for inspecting the object?
Could you create your own description method in a category on
NSDictionaryand print out the contents manually rather than relying on the dictionary’s description method?There could be a bigger problem at hand here, in that dictionaries retain their contents. If you’re adding an object to a dictionary, it gets retained, and then if you’re adding the containing dictionary to the “sub” dictionary, it retains its parent. This will probably result in a retain cycle and probably prevent any of the objects getting deallocated.
From “Cocoa Programming for Mac OS X” by Aaron Hillegass: