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 trialMichael Snyder
Courses Plus Student 7,502 PointsHelp with this please.
Object Oriented Objective-C Challenge Task 3 of 3
NSArray *shoeOrder = @[@"Charles Smith", @(9.5), @"loafer", @"brown"];
NSMutableDictionary *shoeOrderDict = [[NSMutableDictionary alloc]init];
[shoeOrderDict setValue:@([shoeOrder objectAtIndex:0]) forKey:@"customer"];
[shoeOrderDict setValue:@([shoeOrder objectAtIndex:1]) forKey:@"size"];
[shoeOrderDict setValue:@([shoeOrder objectAtIndex:2]) forKey:@"style"];
[shoeOrderDict setValue:@([shoeOrder objectAtIndex:3]) forKey:@"color"];
3 Answers
Keli'i Martin
8,227 PointsYou should be using setObject:forKey
, not setValue:forKey
.
Hope that helps!
Michael Snyder
Courses Plus Student 7,502 PointsSo you are saying I could've done :
[shoeOrderDict setValue:[shoeOrder objectAtIndex:0] forKey:@"customer"];
or...
[shoeOrderDict setValue:@[shoeOrder objectAtIndex:0] forKey:@"customer"];
??
Keli'i Martin
8,227 PointsNo, what I'm saying is setValue:forKey:
and setObject:forKey:
would have both worked to solve the challenge. You don't want to do @[shoeOrder objectAtIndex:0]
because that is not correct syntax. The @[]
is used to define an array, which is not what you're doing here. You're actually calling a method ([shoeOrder objectAtIndex:0]
).
So, in a nutshell:
[shoeOrderDict setValue:[shoeOrder objectAtIndex:0] forKey:@"customer"];
and
[shoeOrderDict setObject:[shoeOrder objectAtIndex:0] forKey:@"customer"];
both would have worked.
Michael Snyder
Courses Plus Student 7,502 PointsO ok. Make sense. Thanks for the clarification!
Michael Snyder
Courses Plus Student 7,502 PointsMichael Snyder
Courses Plus Student 7,502 Pointsyep! just gave you a big thanks on another question thread!
Keli'i Martin
8,227 PointsKeli'i Martin
8,227 PointsYou know, going back, the problem isn't actually
setObject:
vssetValue:
. Both actually will work. What you have above isn't working because you don't need to put[shoeOrder objectAtIndex:0]
inside the@( )
. Apologies! :)