I have a NSMutableArray
named animals. I need to create an NSMutableDictionary
such that all names in the animals array have Keys
that start with a specific first letter = Values
.
This is animals array :
NSMutableArray *animals = [NSMutableArray arrayWithObjects:@"Bear", @"Black Swan", @"Buffalo", @"Camel", @"Cockatoo", @"Dog", @"Donkey", @"Emu", @"Giraffe", @"Greater Rhea", @"Hippopotamus", @"Horse", @"Koala", @"Lion", @"Llama", @"Manatus", @"Meerkat", @"Panda", @"Peacock", @"Pig", @"Platypus", @"Polar Bear", @"Rhinoceros", @"Seagull", @"Tasmania Devil", @"Whale", @"Whale Shark", @"Wombat", nil];
this is my code to set it into a MutableDictionary
:
for(NSString *str in animals) {
NSString *firstLetter = [str substringToIndex:1];
NSArray *newArr = [NSArray arrayWithObject:str];
[myMutableDictionary setValue:newArr forKey:firstLetter];
}
The problem is that for each key only one value is set, but i need all the objects have a first letter with the same value. E.g. value='b' -> @"Bear", @"Black Swan", @"Buffalo".