struct Rect {
var width : Double
init(){
width = 10.0
}
}struct Rect {
var width : Double
var height : Double = 10.0
init(Square square : Double){
width = square
}
init(Rectangle rectangle : Double){
width = rectangle
}
func description (){
println("width is \(width)")
}
}
var graph : Rect = Rect(Square: 10)
var graph2 = Rect(Rectangle: 20)
graph.description()
graph2.description()struct Rect {
var width : Double = 10.0
var height : Double = 10.0
}
var graph : Rect = Rect()
struct Rect {
var width : Double = 10.0
var height : Double = 10.0
init (){
}
init (h : Double){
self.height = h
println("h is \(h)")
}
init (printH : Double){
self.init(h : printH)
}
}
var graph : Rect = Rect(printH: 3.2)
var graph2 = Rect(h: 4.3)便利构造器是辅助构造器,我们可以定义一个便利构造器来调用同一个类中的指定构造器,并为其提供参数和默认值。
下次继续。
原文:http://blog.csdn.net/weasleyqi/article/details/44206117