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 trialthomascawthorn
22,986 PointsAdd to your mutableArray with a key of year and value of 1969
I'm trying to add the year 1969 onto my mutable dictionary, but it keeps saying I haven't set it to the right value. I swear I have this set up the same as the example project!
NSDictionary *album = @{@"title":@"Abbey Road", @"artist":@"The Beatles"};
NSMutableDictionary *albumMutable = [NSMutableDictionary dictionaryWithDictionary:album];
[albumMutable setObject:@1969 forKey:@"year"];
1 Answer
Geoff Parsons
11,679 PointsObjectiveC doesn't like int
types (literal numbers) to be used as keys as it wants some form of object. You could either create an NSNumber
object out of 1969, or you could also just set the value as a NSString of "1969" which looks like what you were starting to do. In the latter case all you need to do is add quotes around it:
@"1969"
thomascawthorn
22,986 Pointsthomascawthorn
22,986 PointsThat's odd because xcode is pretty happy with this:
But yes! That has worked, thanks :-)