@interface WeatherService : NSObject
@property (nonatomic, readonly)
NSMutableDictionary *map;
@end
@implementation WeatherService {
NSMutableDictionary *_map;
}
//ленивое значение: геттер создаёт его
//только при первом обращении
- (NSMutableDictionary *)map {
if (_map == nil) {
//2. Creating WeatherMap
_map = [NSMutableDictionary
dictionary];
}
return _map;
}
@end
WeatherService *service =
[WeatherService new];
//1. Перед обращением к отображению
NSMutableDictionary *map = service.map;
//создаётся здесь, один раз