Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Zenek Barburka
Zenek Barburka
7,009 Points

code fine in Xcode but not in challange

I am not sure what's wrong with it, Xcode compiles it just fine

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

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! You're correct, your code compiles just fine, but it's not giving the keys and value pairs they are expecting. Essentially, you have your keys and values backward. First we say the value and then the key. I know this may seem a little backwards especially if you are used to other programming languages. For example, you have the value "Make" at the key "Honda". But we want the value "Honda" at the key "Make".

Take a look:

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

Here we we have the value of "Honda" at the key "Make" and the value of "Accord" at the key "Model".

Hope this helps! :sparkles: