gpt4 book ai didi

ios - 添加到 NSMutableDictionary 而不替换相似的键

转载 作者:行者123 更新时间:2023-11-28 18:57:58 26 4
gpt4 key购买 nike

我正在使用相同的键动态填充 NSMutableDictionary。但是,这样做会替换原始键值。我需要的是附加它而不是替换现有 key 。例如,我需要一个像

这样的结构
    {
@"Key" : @"Value1",
@"Key" : @"Value2",
@"Key" : @"Value3"
}

我知道我可以将创建的每个 NSDictionary 添加到 NSMutableArray,但我的问题来了,因为我需要输入值是 NSDictionary。

目前我有以下替换原始值

  NSMutableDictionary *ripDictionary = [[NSMutableDictionary alloc] init];

for(NSString *ripId in recievedRips){

//SOME OTHER CODE

ripDictionary[@"rip"] = keysAndAttributes;

[data addObject:ripDictionary];
}

最佳答案

来自NSDictionary Reference

A key-value pair within a dictionary is called an entry. Each entry consists of one object that represents the key and a second object that is that key’s value. Within a dictionary, the keys are unique. That is, no two keys in a single dictionary are equal (as determined by isEqual:).

也许你可以修改你的代码来接受像这样的字典:

{
@"Key" : [
@"Value1",
@"Value2",
@"Value3"
]
}

关于ios - 添加到 NSMutableDictionary 而不替换相似的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30145263/

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