// 属性监视器
class Square{
var width:Double = 0 {
willSet{
println("willSet -- newValue = \(newValue), currentValue = \(width)")
}
didSet{
println("didSet -- oldValue = \(oldValue), currentValue = \(width)")
}
}
var girth:Double {
get{
return width * 4
}
set{
println("调用了girth的set方法")
width = newValue / 4
}
}
}
var s = Square()
s.width = 5
s.girth
s.girth = 200
******************************************
// 方法的第一个参数名仅仅是局部参数名,其他参数名既是局部参数名,也是外部参数名
class Calculate{
func sum(num1:Int, num2:Int) -> Int{
return num1 + num2
}
func mul(num1:Int, number2 num2:Int, _ num3:Int) -> Int{
return num1 * num2 * num3
}
}
var c = Calculate()
c.sum(9, num2:10)
c.mul(3, number2:9, 10)
原文:http://www.cnblogs.com/lianfu/p/4999173.html