【Swift】ios开发中巧用 description 打印对象时,打印对象的属性

ios开发中我们打印对象的时候,会直接输出对象地址,这样不方便我们开发。我们可以 巧用 description 打印对象时,输出对象的属性 

 

在oc中直接重写即可。swift中需要遵守Printable协议

看下面的例子

1     override var description: String {
2         let properties = ["属性1", "属性2", "属性3", "属性4"]
3         
4         return "\(dictionaryWithValuesForKeys(properties))"
5     }

 

posted on 2015-05-16 10:54  歌飘渺  阅读(1277)  评论(0编辑  收藏  举报

导航