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 trialthanh trung
4,246 Pointshaving problem with NSDictionary
<code> NSDictionary *ablbum = [[NSDictionary alloc] initWithObjectsAndKeys:@"title", @"Abbey", @"artist", @"The Beatles", nil ]; </code>
5 Answers
Patrick Donahue
9,523 PointsCan you post the code that you have? I am not sure what the issue is. I put the code in my Xcode and ran it and got it to load in the console.
NSDictionary *album = [[NSDictionary alloc] initWithObjectsAndKeys:@"title", @"Abbey", @"artists", @"The Beatles", nil];
NSLog(@"%@", album);
2014-03-18 09:33:13.269 ] {
Abbey = title;
"The Beatles" = artists;
}
Scott Evans
4,236 PointsHey Thanh, please see the code below.
NSDictionary *album = [[NSDictionary alloc] initWithObjectsAndKeys:@"Abbey Road", @"title", @"The Beatles", @"artist", nil ];
To explain, The 2 things that were wrong were you were declaring the Key / Pairs in the wrong order. When using initWithObjectsAndKeys
you declare them like @"VALUE",@"KEY",@"VALUE",@"KEY"
The only other thing was you put @"Abbey"
instead of @"Abbey Road"
.
Hope this helps
Patrick Donahue
9,523 PointsI didn't even realize they were in the wrong order. :-(
Scott Evans
4,236 PointsIt took me a minute to realise, but then i looked at your console output Abbey = title
then the lightbulb came on in my head :D
Patrick Donahue
9,523 PointsIt looks right to me. But if you are doing a challenge you have album spelled wrong.
NSDictionary *ablbum should be NSDictionary *album
thanh trung
4,246 Pointsi know , i changed it but it still gave me an error message. it said " NSDictionary doesnt have any value". i have tried with xcode it work fine
thanh trung
4,246 Pointsthanks
Scott Evans
4,236 PointsDont forget to Assign best answer so that others can see that this has been solved and possibly benefit from the help
thanh trung
4,246 Pointsthanh trung
4,246 Pointswhats wrong with the code?