在使用kvc给model赋值的时候
重写setValue(value: AnyObject?, forUndefinedKey key: String)
若想在model中使用数组,则应该将model所对应的字典中的数组这个键从model中去除,起一个其他的名字
例如 :dic ={shop_id: "39", shopname: "lulu", count_goods: 2, goods_list:[,,]}
model属性:
shop_id: "39",
shopname: "lulu",
count_goods: 2,
goods_list: 改变键为其他值,例: goods_model_list:
override func setValue(value: AnyObject?, forUndefinedKey key: String) {
if key == "goods_list" {
for dic in (value as! NSArray) {
let model = OrderGoodsModel()
model.setValuesForKeysWithDictionary(dic as! [String : AnyObject])
self.goods_model_list.addObject(model)
}
}
}