码迷,mamicode.com
首页 > 其他好文 > 详细

setNilValueForKey:could not set nil as the value for the key distance.解决方案

时间:2015-07-22 22:59:19      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:ios开发   nsarray   dictionary   


在做小项目的时候,解析json数据以后,将其赋给字典或数组时,出现了这个错误。
主要原因是:赋值的value值为nil,而NSDictionary和NSArray存储对象不能为nil,只能为OC对象。


‘[<CinemaModal 0x7fb2a8558c50> setNilValueForKey]: could not set nil as the value for the key distance.‘

此处是赋给distance变量的值为nil
那么可以重写方法

- (void)setNilValueForKey:(NSString *)key;
- (void)setNilValueForKey:(NSString *)key {
    if ([key isEqualToString:@"distance"]) {
        _distance = 0;
    }else {
        [super setNilValueForKey:key];
    }
}

至于distance取值多少,结合项目进行取合理值处理。

版权声明:本文为博主原创文章,未经博主允许不得转载。

setNilValueForKey:could not set nil as the value for the key distance.解决方案

标签:ios开发   nsarray   dictionary   

原文地址:http://blog.csdn.net/zsk_zane/article/details/47009731

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!