// declare a class
class Wall {
var length: Double
// initializer to initialize property
init() {
length = 5.5
print("Creating a wall.")
print("Length = ", length)
}
}
// create an object
var wall1 = Wall()
class Bike {
var name = ""
}
...
// create object
var bike = Bike()
class Bike {
// properties with no default values
var name: String
var gear: Int
// assign value using initializer
init(name: String, gear: Int){
self.name = name
self.gear = gear
}
}
// object of Person with custom initializer
var bike1 = Bike(name: "BMX Bike", gear: 2)
print("Name: (bike1.name) and Gear: (bike1.gear)")
class Wall {
...
// create an initializer
init() {
// perform initialization
...
}
}
// declare a class
class Wall {
var length: Double
// initializer to initialize property
init() {
length = 5.5
print("Creating a wall.")
print("Length = ", length)
}
}
// create an object
var wall1 = Wall()
class Wall {
var length: Double
...
// initializer with parameter
init(length: Double) {
self.length = length
}
}
// create an object
var wall1 = Wall(length: 10.5)