How come whenever I add a new object NSMutableDictionay to my NSMutableArray it replaces my previous object?
For example:
[appDelegate.tracksDict setObject:currentTrackTitle forKey:@"track_title"];
[appDelegate.tracksDict setObject:currentTrackTopic forKey:@"topic"];
[appDelegate.tracksArray addObject:[appDelegate.tracksDict copy]];
Its printing…
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Cold Calling";
"track_title" = "Sleeping and selling";
}
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Gate Keeper";
"track_title" = "Selling like a chicken";
}
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Gate Keeper";
"track_title" = "Don't you try to sell";
}
Instead of something like…
2010-10-01 14:03:35.021 XML[48889:207]Tracks Array: {
topic = "Cold Calling";
track_title = "Sleeping and selling";
topic = "Gate Keeper";
track_title = "Selling like a chicken";
topic = "Gate Keeper";
track_title = "Selling like a chicken";
}
I’m sure its something stupid since I don’t know the language very well.
Your question is hard to follow based on the “print” you posted, but it sounds like you want an NSArray of NSDictionary objects. NSDictionary can only hold a single object for a given key but can have (virtually) unlimited keys. It looks like what you need is to build an array of dictionaries, one per track.