naomi naomi - 7 months ago 11
iOS Question

Fetching separate values from NSDictionary

I have map my data in a NSDictionary. The data is mapped with one key and multiple values.

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
int count = 1;
int intval=111;
int intval2 = 222;
[dict setObject:[NSString stringWithFormat:@"%d,%d",intval,intval2]

How will I fetch both integer value for a key like for
? I need to get value 111,222 separately in integer variables.


First thing first you can not addObject(this method is for NSMutableArray) into dictionay, You can setObject or Setvalue for any key.

If you are inserting record same as above and there are two integers separated by comma only than you can get it using below way:

NSString *myBothvalue = [dict valueForKey:@"count"];
NSArray *temp = [myBothvalue componentsSeparatedByString:@","];

NSInteger value1 = [[temp objectAtIndex:0] integerValue];
NSInteger value2 = [[temp objectAtIndex:1] integerValue];

Hope this will help you.