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 trialKyle Melton
6,664 PointsMy code accomplished the task but I am not getting a success response. What gives?
I'm sure I'm just not using the exact code the app is checking for but I can't find syntax examples for "addObjectAtIndex".
NSArray *shoeOrder = @[@"Charles Smith", @(9.5), @"loafer", @"brown"];
NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc] init];
[shoeOrderDict setObject:shoeOrder[0] forKey:@"customer"];
[shoeOrderDict setObject:shoeOrder[1] forKey:@"size"];
[shoeOrderDict setObject:shoeOrder[2] forKey:@"style"];
[shoeOrderDict setObject:shoeOrder[3] forKey:@"color"];
2 Answers
Chase Marchione
155,055 PointsHi Kyle,
Here's a source concerning how to use the objectAtIndex instance method: https://www.techotopia.com/index.php/Working_with_Objective-C_Array_Objects#Accessing_the_Elements_of_an_Array_Object.
The syntax is '[array objectAtIndex:index]':
NSArray *shoeOrder = @[@"Charles Smith", @(9.5), @"loafer", @"brown"];
NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc] init];
[shoeOrderDict setObject:[shoeOrder objectAtIndex:0] forKey:@"customer"];
[shoeOrderDict setObject:[shoeOrder objectAtIndex:1] forKey:@"size"];
[shoeOrderDict setObject:[shoeOrder objectAtIndex:2] forKey:@"style"];
[shoeOrderDict setObject:[shoeOrder objectAtIndex:3] forKey:@"color"];
Hope this helps!
Janson Roberts
5,071 PointsThank you so much! This answer was the best one out of the other threads. This helps explain the process of how it works and why as well as help with the answer. =)
Kyle Melton
6,664 PointsKyle Melton
6,664 PointsThank you! I was able to complete the challenge. Now my OCD of an incomplete challenge is satiated.