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

iOS Object-Oriented Objective-C Memory, Arrays and Loops, Oh My! Alloc and Init

i don't understand this, what should i do?

i don't know how I'm going further with this.

variable_assignment.mm
NSMutableDictionary * carDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Accord",@"Model",@"Honda",@"Make", nil];
NSString *myRide;
myRide =[[NSString alloc] init] 

2 Answers

Ahmet GULER
Ahmet GULER
7,181 Points

Hello,

I have the same problem.. please help. Can't get through the challenge. challenge says: 'Do this all in one line of code.'

please if someone can give also an example of both 1 line of code. and also 3 lines of code variant..

Here what i have tried and failed:

NSMutableDictionary *carDict = [NSMutableDictionary alloc] initWithObjectsAndKeys: @"Make":@"Honda", @"Model":@"Accord", nil];

error was:

expected ']' NSMutableDictionary *carDict = [NSMutableDictionary alloc] initWithObjectsAndKeys: @"Make":@"Honda", @"Model":@"Accord", nil];; ^ 1 error generated.

another variant i also couldn't pass through preview is:

NSMutableDictionary *carDict; carDict = [NSMutableDictionary alloc]; [car initWithObjectsAndKeys: @"Make":@"Honda", @"Model":@"Accord", nil];

//In the video it writes test for testDict. so, i wrote car for carDict

error was:

use of undeclared identifier 'car' [car initWithObjectsAndKeys: @"Make":@"Honda", @"Model":@"Accord", nil]; ^ 1 error generated.

i removed the car.. this time error was :

use of undeclared identifier 'initWithObjectsAndKeys' [initWithObjectsAndKeys: @"Make":@"Honda", @"Model":@"Accord", nil]; ^ 1 error generated.

please help to understand

ARMANDO RODRIGUEZ
ARMANDO RODRIGUEZ
4,216 Points

Okay guys, I figured it out and it's stupid and they should fix it.
For some reason, Make:Honda and Model:Accord are reversed. Model:Accord should be the first object in the dictionary.

NSMutableDictionary *carDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Accord",@"Model",@"Honda",@"Make", nil];  

That will past first question.

NSString *myRide = [[NSString alloc] init];

This will past second question. You need to allocate and initialize but do not declare a value for the string.

myRide = [carDict valueForKey:@"Model"];

This will pass third question because you are telling it to assign the value of the key "Model" to the string you already allocated, myRide. You don't need to put a pointer again because the pointer was already declared.