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 Build a Blog Reader iPhone App Data Modeling Creating a Custom Class: Part 1

Adham Gad
Adham Gad
9,899 Points

Can't understand the concept behind creating a custom class

In the blog reader app Amit created a custom class instead of using a dictionary and he explained that by saying "Storing structured data inside a dictionary is not considered practical" And he said "You cannot retrieve a value unless u know its key,a better solution is to create a custom class" but i think we will also need to know the keys when we use a blogpost object to assign the values of the dictionary to it Why is creating a blogpost object is better than using the dictionary ? same with the Playlist app made by Pasan

Stepan Ulyanin
Stepan Ulyanin
11,318 Points

By "practical" Amit didn't mean more convenient to instantly use the data; remember the Model-View-Controller concept? In programming it is very important to make your code and programs first of all readable and second of all reusable. That is the concept behind creating a separate class to store data in it (our model) so, let's say, if we create another view we would not have to access dictionary from the table view - it will be very confusing for other coders to read (they will have to trace the model all over the views and stuff). So if you use one separate class to store your model (in this case it is dictionary, and you are right you still have to use keys) at least it will be more readable for programmers, or if you make another view, you can reuse your model by just creating an instance of the model class in the new view controller (or some other controller). Hope this helps