Swift Tutorial - Tutorialspoint

(backadmin) #1
self.tuesday = tuesday

}

init(daysofaweek: Int) {
sunday = daysofaweek
monday = daysofaweek
tuesday = daysofaweek
}
}

let week = Days(sunday: 1 , monday: 2 , tuesday: 3 )
println("Days of a Week is: \(week.sunday)")
println("Days of a Week is: \(week.monday)")
println("Days of a Week is: \(week.tuesday)")

let weekdays = Days(daysofaweek: 4 )
println("Days of a Week is: \(weekdays.sunday)")
println("Days of a Week is: \(weekdays.monday)")
println("Days of a Week is: \(weekdays.tuesday)")

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


Days of a Week is: 1
Days of a Week is: 2
Days of a Week is: 3
Days of a Week is: 4
Days of a Week is: 4
Days of a Week is: 4

Parameters without External Names


When an external name is not needed for an initialize underscore '_' is used to override
the default behavior.


struct Rectangle {
var length: Double

init(frombreadth breadth: Double) {
Free download pdf