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 @   黄增松  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示