KVC中setValuesForKeysWithDictionary 崩溃问题
来源:互联网 发布:网络教育考公务员 编辑:程序博客网 时间:2024/06/16 00:42
KVC 是键值编码,一个非正式的 Protocol ,提供一种机制来间接访问对象属性,KVO 就是基于 KXC 实现的关键技术之一
在字典数组转模型数组时,使用这个setValuesForKeysWithDictionary,不用自己一一的给对象赋值而根据匹配类中与字典key同名的属性,并赋值给属性从而能预防自己匹配key 错误和减少代码代码量。
执行完setValuesForKeysWithDictionary这个方法后只要对象中都包含了这些键值都有值了
但注意如果JSON里面的id和属性(模型属性)里面的id没有一一对应,我现在注释掉一个属性,再运行程序
控制台就是给我们报这样的错误:
直接导致程序崩溃,解决方法就是,实现一个方法setValue:forUndefinedKey:
过滤掉给不存在的键值赋值,运行程序就不会崩溃了
0 0
- KVC中setValuesForKeysWithDictionary 崩溃问题
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:详解
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary
- KVC中setValuesForKeysWithDictionary用法
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary:
- KVC中setValuesForKeysWithDictionary
- Volley 的介绍和使用(一)
- Delphi 三层框架开发客户端开发
- 全排列_蓝桥杯问题+一点对递归的看法
- C++使用模板并隐藏实现
- HTML5新控件 - 日期和时间选择输入
- KVC中setValuesForKeysWithDictionary 崩溃问题
- Android 开关机动画
- ShareSDK For IOS
- 细数iOS上那些你绝对不会注意到的神细节
- caffe代码阅读5:Layer的实现细节-2016.3.17
- apache tomcat 集群
- python 刷题:二维数组中的查找
- 使用Handler来对线程之间传值
- PHP过滤重复的值