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 trialDáithí Ó Raghallaigh
Courses Plus Student 585 PointsHi guys. For some reason your site isn't allowing me to pass this working code.
NSMutableDictionary *carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Make" , @"Honda", @"Model" , @"Accord", nil];
But your site says it is wrong and to check my syntax :)
Any ideas??
Thanks in advance D
NSMutableDictionary *carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Make" , @"Honda", @"Model" , @"Accord", nil];
1 Answer
Stuart Wright
41,120 PointsAlthough the way you've done it would seem more intuitive (to me, at least), you actually have the keys and values the wrong way around. The value comes before the key for each pair, according to the documentation:
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil];
https://developer.apple.com/documentation/foundation/nsdictionary/1574190-initwithobjectsandkeys
Dáithí Ó Raghallaigh
Courses Plus Student 585 PointsDáithí Ó Raghallaigh
Courses Plus Student 585 PointsThanks so much!!! I knew it had to be something simple like that as my coding was fine. That little line drove me mad for hours :) Finally passed it!!
The answer was: NSMutableDictionary *carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Honda" , @"Make", @"Accord" , @"Model", nil]; NSString *myRide = [[NSString alloc] init]; myRide = [carDict valueForKey:@"Make"];