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 trialAndre Robinson
Courses Plus Student 6,057 PointsPlease help it ask me to set values I'm so lost
This problem is confusing to me
NSMutableDictionary* carDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Honda",@"Make",@"Accord",@"Model",nil];
NSString * myRide = [[ NSString alloc] initWithObjects: @"Make"];
1 Answer
Anjali Pasupathy
28,883 PointsYou're nearly there. NSString doesn't use initWithObjects; however, you could use initWithString.
If you just replace initWithObjects with initWithString, you'll be assigning the string @"Make" to myRide. That's not what we're trying to do. What we want to do is get the value for the key @"Make" from carDict, and set that value to myRide. The method we can use to get the value for the key @"Make" from carDict is valueForKey:
[carDict valueForKey: @"Make"];
You need to put that method in square brackets so Objective-C can recognize that these words go together as a single unit. In this case, that unit returns an NSString with the value @"Honda", which is what we're trying to do.
Now, all you have to do is use that unit as the argument for initWithString when you're initializing myRide:
NSString * myRide = [[NSString alloc] initWithString: [carDict valueForKey: @"Make"]];
I hope this helps!