I have a property:
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSMutableDictionary<NSString *, NSString *>*>*mainDict;
So it is a dictionary with another dictionary as its value. Now, when I wanna populate my dictionary, I do:
NSData *data = [json_string dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
for (NSString *key in [[json objectForKey:@"countries"] allKeys]) {
NSDictionary *innerDictionary = [json objectForKey:@"countries"][key];
[mainDict setObject:innerDictionary forKey:key];
}
when I debug, I see that my innerDictionary
is correct and has its values but somehow my mainDict is not being filled.
Could you please tell me what I do wrong?
Declaring mainDict as a @property will create an instance variable in your class, but that variable will be nil.
You'll need to initialize the mainDict somewhere before your population code gets called, perhaps in your -init, -viewDidLoad, or somewhere appropriate for your app's architecture.
mainDict initialization should look like:
mainDict = [[NSMutableDictionary alloc] init];