Swift iOS Interview : All about Property and Property Observer
Property : Properties are associated values with a particular class, struct & enum.
Property are basically two types.
1. Stored Property :
Store property can store variable and constant.
Store property given by class & struct.
Store property can’t be define in extension.
2. Computed Property :
Computed property calculate rather than store.
Computed property given by class, struct & enum.
Computed property are always variable.
Computed property provide getter & optional setter
Lazy Stored Property :
A property whose initial value is not calculated till the time of its use.
Lazy stored property is always variable.
Application of Lazy properties : When the initial value for a property is dependent on outside factors whose values are not known until after an instance’s initialization is complete.
class GPS {
init() {
print("Initializing GPS...")
}
}
class Car {
lazy var navigation = GPS()
}