Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndre Robinson
Courses Plus Student 6,057 PointsPlease help
I don't know what I'm doing wrong
NSArray * shoeOrder = @[ @"Charles Smith",@(9.5),@"loafer",@"brown"];
NSMutableDictionary * shoeOrderDict = [[NSMutableDictionary alloc] init];
NSMutableDictionary * shoeOrder = [[NSMutableDictionary alloc] objectAtIndex : 'customer','size','style','color'];
2 Answers
Anjali Pasupathy
28,883 PointsYou're nearly there. Your last line is a bit buggy, though.
You want to use two methods: the setValue:forKey: method on shoeOrderDict, and the objectAtIndex: method on shoeOrder.
The setValue:forKey: method has the following syntax:
[shoeOrderDict setValue: /* INSERT VALUE HERE */ forKey: /* INSERT KEY HERE */];
This method can only take one key-value pair at a time, so you'll have to use it 4 times in your code.
The keys are the NSString literals given in the challenge: @"customer", @"size", @"style", and @"color". The values are the contents of the array. While you could access each member of the array with subscript syntax (i.e. shoeOrder[0], etc.), this challenge wants you to use the objectAtIndex: method on shoeOrder to access the elements in the array.
The objectAtIndex: method has the following syntax:
[shoeOrder objectAtIndex: /* INSERT INDEX HERE */];
Putting the two methods together, each line of code adding a key-value pair should look like this:
[shoeOrderDict setValue: [shoeOrder objectAtIndex: /* INSERT INDEX HERE */] forKey: /* INSERT KEY HERE */];
I hope this helps!
Christian A. Castro
30,501 PointsNSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
[shoeOrder objectAtIndex:0], @"customer",
[shoeOrder objectAtIndex:1], @"size",
[shoeOrder objectAtIndex:2], @"style",
[shoeOrder objectAtIndex:3], @"color",
nil];
hope this helps you!!!