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 trial

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