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

NSDictionary/NSMutableDictionary, literals and key,object sequence.

I need a grey area cleared up regarding 'key/object' sequence vs 'object/key' sequence. So I guess the question is if you use literals when defining dictionary is the sequence always going to be 'key/object' regardless of NSDictionary or NSMutableDictionary. OR does the 'Key/Object' sequence always apply to NSMutableDictionary.

Also when adding to a mutableDictionary is the adding sequence flexible, for example from video it is being added 'object then key' can that sequence be reversed please reference below code from video

//Adding to dictionary, sequence as presented in video [mutableBook setObject:@"1957" forKey:@"year"];

//Can that be written in the following more logical way in line with a //key/object sequence when adding as it feels it would be more tidy [mutableBook forKey:@"year" setObject:@"1957" ];

Sorry the way last two lines turned out, I'm sure you will understand, it presented well in browser before submitting it i must have not pressed enter where two lines joined up.

1 Answer

I would look at this

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/setObject:forKey:

But as far as I can see it does not look like you can write it the second way. Someone feel free to correct me if I'm wrong.