6.使一个已有类型符合某个协议
一、扩展属性,构造器,方法
class Human{ var name:String? var score:Double init(name:String,score:Double){ self.name = name self.score = score } } extension Human{ var scale:Double{ //扩展计数属性类型 return Double(score)/60 } convenience init(){ //扩展便利构造器 self.init(name:"小笨狼",score:60) } func description(){ //扩展方法 println("name:\(name),score:\(score)") } }
Swift 学习笔记十五:扩展,布布扣,bubuko.com
原文地址:http://blog.csdn.net/xbenlang/article/details/32320827