崩溃之前的代码
NSMutableDictionary *item = [NSMutableDictionary dictionaryWithDictionary:guaranteedModeDict]; NSMutableDictionary *modelDict = item[MODEL]; [modelDict setValue:[[NSString stringWithFormat:@"%f",minimoney] showShortPriceString] forKey:@"miniMoney"];
崩溃在第三行,字典setValue。
原因是item是可变字典,但是 item[MODEL] 是不可变字典。虽然 modelDict 是可变字典,但是指向了一个不可变字典,最终导致 modelDict 也成了不可变字典。NSMutableDictionary 有 setValue,NSDictionary 无 setValue,崩溃
修改后的代码
NSMutableDictionary *item = [NSMutableDictionary dictionaryWithDictionary:guaranteedModeDict]; NSMutableDictionary *modelDict = [item[MODEL] mutableCopy]; [modelDict setValue:[[NSString stringWithFormat:@"%f",minimoney] showShortPriceString] forKey:@"miniMoney"];
标签:__,setValue,NSDictionaryI,NSMutableDictionary,item,modelDict,MODEL,字典 From: https://www.cnblogs.com/huangzs/p/18243970