Hi,
I'm writing an app in XCode 3.2.3 for iOS 4. In my code, I am creating an NSArray of NSDictionaries, each containing two key/value pairs, a string and an NSArray of NSDictionaries (kind of confusing, I know). Just to give you a visual, here is the structure:
<NSArray>
<NSDictionary>
<NSString/>
<NSArray>
<NSDictionary/>
<NSDictionary/>
...
</NSArray>
</NSDictionary>
...
</NSArray>
What's weird is that when I add a new NSDictionary to the innermost NSArray, it seems to add the same dictionary to the NSArray contained within each of the outer NSDictionaries. Here's how I'm adding the innermost NSDictionary to the innermost NSArray:
[[outerDict objectForKey:@"innerArray"] addObject:innerDict];
So, just to recap, the output I want is something like this:
<outerArray>
<outerDict1>
<string>
<innerArray1>
<innerDict1>
<innerDict2>
</innerArray1>
</outerDict1>
<outerDict2>
<string>
<innerArray2>
<innerDict3>
<innerDict4>
</innerArray2>
</outerDict2>
<outerArray>
But what I'm actually getting is this:
<outerArray>
<outerDict1>
<string>
<innerArray1>
<innerDict1>
<innerDict2>
<innerDict3>
<innerDict4>
</innerArray1>
</outerDict1>
<outerDict2>
<string>
<innerArray2>
<innerDict1>
<innerDict2>
<innerDict3>
<innerDict4>
</innerArray2>
</outerDict2>
<outerArray>
Notice that the inner NSDictionaries are added to every innerArray. For the life of me I can't figure out why!!
Any help would be very greatly appreciated, thank you!
-Matt