美文网首页
swift 模型+打印出模型信息

swift 模型+打印出模型信息

作者: 陈水寒 | 来源:发表于2017-11-08 11:03 被阅读31次

备注:swift4.0 需要在类的上面加上@objcMembers,否者会报错

1、定义属性

    var code : String?
    var png : String?
    var chs : String?

2、自定义构造函数

    init(dict : [String : String]) {
        super.init()
        
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
    

3、重新description方法

    override var description: String {
        return dictionaryWithValues(forKeys: ["code","png","chs"]).description
    }

相关文章

网友评论

      本文标题:swift 模型+打印出模型信息

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