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

A question about NSDictionary

So, I'm just thinking out loud and I'd like to understand something a little more.

If storing structured data in a dictionary isn't considered practical because to access its value we must first know its key, why is it that we're still storing/accessing information in dictionaries?

I'm not questioning the usefulness of dictionaries but more as to why we are told not to store structured data in them given we're accessing remote data that's already stored in a dictionary.

I understand that the "Using a Custom Class" section is to teach us about the usefulness of custom classes and gets us to practice using them as well as adapting our thought process to include them as we build out our applications, but I'm just curious as to why this statement in my second paragraph is made yet inherently we use dictionaries to store data.

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

An NSDictionary is a collection just like an array and it can be useful in a variety of situations. There is no hard and fast rule to create a custom class, however, if you are using a dictionary throughout your app to structure data then you are better off with a custom class. If it is a one-off use case or you need to pass data around then a dictionary is your best friend.

Thanks for your response, Amit! Wow, I've been watching your videos for quite some time now and it's great to interact with you here. Thanks for the clarification -- it makes perfect sense. :)