I have arrays of names and images like below
NSArray *names = [[NSArray alloc] initWithObjects:@"naveen", @"kumar",nil];
NSArray *images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"1.jpg"], [UIImage imageNamed:@"2.jpg"], nil];
I want to create a dictionary in the following format
list:
item 0 : naveen
1.jpg
item 1: kumar
2.jpg
How can i create this one? Please?
You need to do like this :
NSMutableDictionary *nameImageDict=[NSMutableDictionary new];
for (NSInteger i=0; i<names.count; i++) {
NSArray *array=@[names[i],images[i]];
//or in older compiler 4.3 and below
//NSArray *array=[NSArray arrayWithObjects:[names objectAtIndex:i],[images objectAtIndex:i], nil];
[nameImageDict setObject:array forKey:[NSString stringWithFormat:@"item %d",i]];
}
for key item 0: it will have an array. The array contains name and image.
Like this:
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:images andKeys:names];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With