@interface WeatherService : NSObject
@property (nonatomic, readonly)
NSMutableDictionary *map;
@end
@implementation WeatherService {
NSMutableDictionary *_map;
}
//lazy: the getter creates the value
//on first access only
- (NSMutableDictionary *)map {
if (_map == nil) {
//2. Creating WeatherMap
_map = [NSMutableDictionary
dictionary];
}
return _map;
}
@end
WeatherService *service =
[WeatherService new];
//1. Before accessing the map
NSMutableDictionary *map = service.map;
//created here, once