swift 后台数据返回模型变量与系统关键字冲突

2016-10-28  本文已影响54人  抬头触摸那yi抹阳光

属性模型创建

import UIKIit
// 定义三个属性变量
class person : NSObject {
    var  name : String ? // 名字
    var  age: String? // 年龄
    var address: String ? // 地址

    init (dict:[String : AnyObjcet]){
    super.init()
    self.setValuesForKeys(dict)
    }
     override func setValue(_ value: Any?, forUndeFinedKey key: String){
    }
  
   // kvc 截获后台数据变量关键字 
     override func setValue(_ value: Any?, forKey: String){
        //   假设后台数据返回有变量名为 description  与系统关键字冲突
        if key == "description"{
           // 我们来用定义的 address 来代替 description 的值
           address = varlue as! String?
      }
        super.setValue(value, forKey: key)
    }
}



上一篇下一篇

猜你喜欢

热点阅读