xxxxxxxxxx
struct Person {
// define two properties
var name: String
var age: Int
}
// object of Person with memberwise initializer
var person1 = Person(name: "Dwight", age: 43)
print("Name:", person1.name)
print("Age:", person1.age)
xxxxxxxxxx
struct Person {
// properties with no default values
var name: String
var age: Int
}
// instance of Person with memberwise initializer
var person1 = Person(name: "Kyle", age: 19)
print("Name: \(person1.name) and Age: \( person1.age)")
xxxxxxxxxx
struct Person {
var name: String
var age: Int
var height: Double
var weight: Double
init(name: String, age: Int, height: Double, weight: Double) {
self.name = name
self.age = age
self.height = height
self.weight = weight
}
}
//inti is member-wise initializer.
xxxxxxxxxx
class Car {
let make: String,
let model: String,
let year: Int
init(make: String, model: String, year: Int){
self.make = make
self.model = model
self.year = year
}
}