<分区>
<分区>
我下面有一个NSMutableArray
(
{
Realimg = "<UIImage: 0x13951b130>, {800, 600}";
"bid_accepted" = 1;
"bid_amount" = 100;
"bid_amount_num" = 100;
"bid_cur_name" = USD;
"bid_cur_symb" = $;
"bid_currencycode" = 4;
"bid_date" = "05 Nov 2015";
"bid_msg" = testing;
"bid_user_id" = 2;
"nego_id" = 612;
"pas_count" = 5;
"ride_address" = "Sample Address";
"ride_cover_img" = "uploadfiles/UploadUserImages/2/mobile/21426739600s-end-horton-plains.jpg";
"ride_id" = 149;
"ride_name" = "Ride to the World's End";
"ride_type_id" = 0;
"ride_type_name" = Travel;
"ride_user_fname" = Nik;
"ride_user_id" = 2;
"ride_user_lname" = Mike;
}
)
我想做的是,替换“bid_currencycode”= 4;按不同的值。我想用 5 替换 4。我该怎么做?请有人帮助我。
谢谢
最佳答案
您可以使用以下代码来执行相同的操作:
// Getting the dictionary from your array and making it to a mutable copy
NSMutableDictionary *dict = [yourArray[index] mutableCopy];
// Changing the specified key
[dict setObject:@(5) forKey:@"bid_currencycode"];
// Replacing the current dictionary with modified one
[yourArray replaceObjectAtIndex:index withObject:dict];
这里:
yourArray
是一个 NSMutableArray
index
是一个有效的索引(对象的索引,你需要改变它的值)关于ios - 如何从 Objective C 中的另一个值替换 NSDictionary 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33545843/
相关文章:
objective-c - 如何在 Objective C 中初始化一个 NSMutableArray?
iphone - 从不同的 View Controller 访问来自 NSJSONSerialization 的数据
objective-c - NSMutableArray:删除所有对象还是初始化一个新的 NSMutableArray 更快?
ios - 向 Journal 的 iOS plist 添加多个词典
ios - 使用初始名称创建 NSDictionary 进行排序
ios - 为什么此 Objective C 代码会因 EXC_BAD_ACCESS code=1 而崩溃? (使用 block 语法和字典)
python - 使用 Twilio 可编程语音 SDK 的通话质量差