美文网首页
swift 后台数据返回模型变量与系统关键字冲突

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

作者: 抬头触摸那yi抹阳光 | 来源:发表于2016-10-28 17:04 被阅读54次

属性模型创建

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)
    }
}



相关文章

网友评论

      本文标题:swift 后台数据返回模型变量与系统关键字冲突

      本文链接:https://www.haomeiwen.com/subject/cujeuttx.html