gpt4 book ai didi

ios - 当数组包含在 NSDictionary 中时设置 NSArray 值?

转载 作者:行者123 更新时间:2023-11-28 22:55:19 25 4
gpt4 key购买 nike

我想在字典的数组中设置项目。我在下面有一个 NSDictionary,一个名为“currentCityNode”的实例。在那个字典中是一个数组项(除其他外)。数组项称为“TheConnections”下面的代码成功读取了数组。

 NSArray *theConnectionsArray = [currentCityNode objectForKey:@"TheConnections"];
(theConnectionsArray now contains the previously loaded values '3','7', and '9')

现在我想在此数组中设置一个值。将第二个值“7”设为“5”。

我已经尝试了一些变体,但还不能得到它。

[currentCityNode addObject:notsurewhattoputhere forKey:@"TheConnections"];

最佳答案

你的数组和字典必须是可变的,像这样的东西应该可以工作。如果 ConnectionsArray 已经是可变的,那么您将不必使用 mutableCopy

NSMutableArray *theConnectionsArray = [[currentCityNode objectForKey:@"TheConnections"] mutableCopy];
[theConnectionsArray replaceObjectAtIndex:1 withObject:@"5"];
[currentCityNode setObject:theConnectionsArray forKey:@"TheConnections"];

关于ios - 当数组包含在 NSDictionary 中时设置 NSArray 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10924591/

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