Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Objective-C Memory, Arrays and Loops, Oh My! Review Dictionaries and Arrays

How to fix expected identifier with NSMutableDictionary?

NSArray *shoeOrder = @[@"Charles Smith",@(9.5),@"loafer",@"brown"];

NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc] init];

NSMutableDictionary *shoeOrderDict [[NSMutableDictionary]objectAtIndex:0];

This is my full code, I am trying to add the values in the Array into the NSMutableDictionary, must use objectAtIndex.

variable_assignment.mm
 NSArray *shoeOrder = @[@"Charles Smith",@(9.5),@"loafer",@"brown"];

    NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc] init];

    NSMutableDictionary *shoeOrderDict [[NSMutableDictionary] objectAtIndex:0];

2 Answers

Emil Rais
Emil Rais
26,819 Points

You performed correctly the first step where you allocate and initialise your dictionary. The next thing you need to do is to assign each value from the array to the dictionary using the corresponding key.

So you would do something like the following 4 times - once for each key.

shoeOrderDict[@"key"] = [shoeOrder objectAtIndex: index]
Janson Roberts
Janson Roberts
5,071 Points

This didn't work for me. Still stuck...not fully even understanding how this is supposed to work for multiple objectAtIndex. What's wrong here?