views:

33

answers:

1

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.

+1  A: 

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.

Joshua Nozzi
And the output the OP provided looks more like a dictionary of arrays. An array of dictionaries is a better idea.
Alex
I edited my question. Sorry I had made a mistake. It should be an Array of Dictionaries as you guys said. But whenever I add a new dictionary it is replace the pervious one I had added. Instead of retaining all of the Dictionaries.
slowman21
Urgh, nevermind I have misunderstood completely what I was trying to accomplish. Thanks anyway guys. I need to ask better questions next time.
slowman21
Better questions not only lead to better answers from others, but they can often lead you to your own answer. :-) Sometimes just taking the time to phrase a question carefully is enough to clarify the problem so the solution is obvious before even asking.
Joshua Nozzi