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 trialvdhd ffj
335 PointsHow to declare an NSMutableDictionary?
hai,what wrong with my code,how to write ,I dont konw ,give me some help,thank you.
NSMutableDictionary *carDict = [NSMutableDictionary alloc];
[carDict initwithObjectsAndKeys:@"Honda",@"Make",@"Accord",@"Model",nil];
2 Answers
Amit Bijlani
Treehouse Guest TeacherYou are almost right. Firstly, the method names are case sensitive so make sure you are using the right capitalization. Your method nameinitwithObjectsAndKeys
should be with a capital i
.
Secondly, you want to declare it all in one line:
NSMutableDictionary *carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Honda",@"Make",@"Accord",@"Model",nil];
Amit Bijlani
Treehouse Guest TeacherThe third step says: "Set the value of 'myRide' to the value of "Make" contained in 'carDict'."
What it is asking you to do is assign the value of the key Make
contained in the dictionary variable named carDict
to the variable myRide
. You need to use the method to get the value out of the dictionary. You need to use the method valueForKey
to get the value out of the dictionary.
vdhd ffj
335 Pointsvdhd ffj
335 Pointsok,Thank you,but Mr Amit Bijlani,how should I write on the third step,I dont know how to write on the three step. NSMutableDictionary *carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Honda",@"Make",@"Accord",@"Model",nil];
NSString *myRide = [[NSString alloc] init]; Thank you for your answer.