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 trialbronnyreinhardt
1,007 PointsAdding different classes to NSMutableDictionary
In the following code, I can only add one type of value using NSMutableDictionary, in this case integers.
int main()
{
NSDictionary *book = @{@"title":@"The Cat in the Hat", @"author":@"Dr. Seuss"};
NSLog(@"book %@", book);
NSMutableDictionary *mutableBook = [NSMutableDictionary dictionaryWithDictionary:book];
[mutableBook setObject:@1957 forKey:@"year"];
[mutableBook setObject:@50 forKey:@"extent"];
NSLog(@"%@", mutableBook);
return 0;
}
What if I wanted to make the key 'extent' return the value 'fifty' (i.e. a string instead of an integer)? Do I have to create another NSMutableDictionary?
Navid Mirzaie Milani
6,274 PointsNavid Mirzaie Milani
6,274 PointsYou can put every Object in an NSDictonary you want ;), if you want to store a object that points to a class you are free to do that.