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 trialARMANDO RODRIGUEZ
4,216 PointsOn the quiz, you must be checking code wrong. I wrote my alloc init one line, three different ways, all failed...
[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Make",@"Honda",@"Model",@"Accord",nil];
This failed.
[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Make",@"Honda",@"Model",@"Accord",nil];
This also failed.
Please fix your code check.
3 Answers
jcorum
71,830 PointsHere you go:
NSDictionary *carDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Honda",@"Make",@"Accord",@"Model", nil];
NSString *myRide = [[NSString alloc] init];
myRide = [carDict valueForKey: @"Make"];
Mark Reid
1,948 PointsThe problem with this code in this question is that the objects and keys are reversed.
They should be @"Honda",@"Make",@"Accord",@"Model"
.
You have them as @"Make",@"Honda",@"Model",@"Accord"
.
Subtle difference but that's why the code check is failing.
jcorum
71,830 PointsKris, I just tried it again (https://teamtreehouse.com/library/objectoriented-objectivec/memory-arrays-and-loops-oh-my/alloc-and-init-2), because sometimes the challenges get changed, but it still worked fine, for all 3 tasks. So I'm not sure what you meant by not passing Step 2.
Kris Rajendren
12,822 PointsThank you. It worked. I was extracting the @"Model" key by mistake instead of @"Make". It was such a simple error that it never even occurred to me to check for it.
Kris Rajendren
12,822 PointsKris Rajendren
12,822 PointsIn step three even with the right code the simulator says Step 2 did not Pass and asks us to go to Step 2 again in a loop.