gpt4 book ai didi

objective-c - NSMutableDictionary 中的编辑条目失败,错误为 : "unrecognized selector sent to instance"

转载 作者:行者123 更新时间:2023-12-03 17:49:21 25 4
gpt4 key购买 nike

我有一个NSMutableDictionary初始化如下:

dictionary = [NSMutableDictionary dictionaryWithDictionary:@{
@"0": @{
@"title": @"Description",
@"value": @"Enter Description",
},
@"1": @{
@"title": @"Amount",
@"value": @"Enter Amount",
}
}];

现在我想修改@"Enter Description"我一直在尝试这样做:

NSMutableDictionary *tempDictionary = [dictionary objectForKey:@"0"];
[tempDictionary setObject:@"TEST" forKey:@"value"];
//The next line doesn't get executed yet since the error occurs at the line above.
//So Maybe there is something wrong with the one below as well ;-)
[dictionary setObject:tempDictionary forKey:@"0"];

但是我收到以下错误消息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance

我发现不知何故我的NSMutableDictionary一定已经变成了NSDictionary ,这就是为什么我无法编辑它。也许您可以帮我解决这个问题,并为我指明正确的方向,或者向我展示可以找到答案的资源?

最佳答案

您的“子词典”是不可变的。

试试这个:

dictionary = [NSMutableDictionary dictionaryWithDictionary:@{
@"0": [NSMutableDictionary dictionaryWithDictionary:@{
@"title": @"Description",
@"value": @"Enter Description",
}],
@"1": [NSMutableDictionary dictionaryWithDictionary:@{
@"title": @"Amount",
@"value": @"Enter Amount",
}]
}];

关于objective-c - NSMutableDictionary 中的编辑条目失败,错误为 : "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32105650/

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