reason: '[<__NSDictionaryI setValue:forUndefinedKey this class is not key value coding-compliant

崩溃之前的代码

    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"];

 

posted @ 2024-06-12 14:57  黄增松  阅读(17)  评论(0编辑  收藏  举报