gpt4 book ai didi

cocoa - 将 NSMutableDictonary 添加到 NSMutableArray 但对象被替换

转载 作者:行者123 更新时间:2023-12-03 18:03:51 24 4
gpt4 key购买 nike

为什么每当我向 NSMutableArray 添加一个新对象 NSMutableDictionay 时,它就会替换我以前的对象?

例如:

[appDelegate.tracksDict setObject:currentTrackTitle forKey:@"track_title"];
[appDelegate.tracksDict setObject:currentTrackTopic forKey:@"topic"];
[appDelegate.tracksArray addObject:[appDelegate.tracksDict copy]];

正在打印...

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";
}

而不是像...

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";
}

我确信这很愚蠢,因为我不太了解这种语言。

最佳答案

根据您发布的“打印”,您的问题很难理解,但听起来您想要一个 NSDictionary 对象的 NSArray 。 NSDictionary 只能保存给定键的单个对象,但可以拥有(实际上)无限的键。看起来您需要的是构建一组字典,每个轨道一个。

关于cocoa - 将 NSMutableDictonary 添加到 NSMutableArray 但对象被替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3842186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com