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 trialChristian Antfeld
1,087 PointsInitializing a dictionary with objects from an array
In the code challenge I am facing, the requirements are to initialize a NSMutable dictionary with objects previously created in an array. The challenge also suggests (requires) that I use the objectAtIndex method/function (sorry if this is not a method or function, it seems like it is to me) to do this and I am not sure how to go about this.
NSArray *shoeOrder = @[@"Charles Smith", @9.5, @"loafer", @"brown"];
NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc] init];
1 Answer
landonferrier
25,097 PointsChristian,
Use this function: (I have already plugged in the variable name for you)
[[NSMutableArray alloc] initWithArray:shoeOrder];
If you have any questions, feel free to ask!
Janson Roberts
5,071 PointsJanson Roberts
5,071 PointsDid you ever find an answer for this challenge? I'm stuck on this one as well. I understand that the code below in the comment: (initWithArray) specifically calls the items from the NSArray shoeOrder to place them in the new mutable dictionary. What I'm stumped with is the "objectAtIndex" code that is calling the specific keys/value pairs. How'd you solve this for answering multiple keys/values in that mutable dictionary?