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 trial
kirhim lee
1,517 PointsAlloc and init
For the challenge alloc and init:
"Create an NSMutableDictionary called 'carDict'. Allocate memory and initialize 'carDict' with the following key/value pairs: "Make":"Honda", "Model":"Accord". Do this all in one line of code."
why is my first code wrong and second correct? why should I write "Honda" and "Accord" in front of "Make" and "model"?
NSMutableDictionary * carDict =
[[NSMutableDictionary alloc] initWithObjectsAndKeys: @"make",@"Honda",@"Model",@"Accord",nil];
NSMutableDictionary *carDict =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Honda", @"Make", @"Accord", @"Model", nil];
2 Answers
miikis
44,957 PointsHi Kirhim,
Not sure what you're asking exactly; that's just how the method signature goes for that method in Objective-C. See the docs.
kirhim lee
1,517 PointsI see thanks!
kirhim lee
1,517 Pointskirhim lee
1,517 PointsIn the code challenge it's in the order of "Make":"Honda", "Model":"Accord".
But when I write the in the code, why should I write in the order of "@"Honda", @"Make", @"Accord", @"Model"?
I hope you get what I am trying to say.
miikis
44,957 Pointsmiikis
44,957 PointsYeah I get what you're saying — the ordering of the parameters for that method is a bit unconventional. But, the answer to your question is: "because that's just the way it works." Such is Objective-C syntax.