class WeatherMap {
let city = "Moscow"
}
class WeatherService {
//значение создаётся при первом обращении
lazy var map = WeatherService.load()
static func load() -> WeatherMap {
print("2. Creating WeatherMap")
return WeatherMap()
}
}
//глобальная переменная ленива сама по себе,
//поэтому "lazy" для неё не допускается
let service = WeatherService()
print("1. Before accessing the map")
print("3. Got the map for", service.map.city)
print("4. Got it again for", service.map.city)
//WeatherMap создаётся только один раз