class WeatherMap {
let city = "Moscow"
}
class WeatherService {
//the value is created on first access
lazy var map = WeatherService.load()
static func load() -> WeatherMap {
print("2. Creating WeatherMap")
return WeatherMap()
}
}
//a global variable is lazy by itself,
//so "lazy" is not allowed on it
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 is created only once