Swift Tutorial - Tutorialspoint

(backadmin) #1
length = breadth * 10
}

init(frombre bre: Double) {
length = bre * 30
}

init(_ area: Double) {
length = area
}
}

let rectarea = Rectangle(180.0)
println("area is: \(rectarea.length)")

let rearea = Rectangle(370.0)
println("area is: \(rearea.length)")

let recarea = Rectangle(110.0)
println("area is: \(recarea.length)")

When we run the above program using playground, we get the following result:


area is: Optional(180.0)
area is: Optional(370.0)
area is: Optional(110.0)

Default Initializers


Default initializers provide a new instance to all its declared properties of base class or
structure with default values.


class defaultexample {
var studname: String?
var stmark = 98
var pass = true
}
var result = defaultexample()
Free download pdf