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.
Hi, I was wondering why we didn't have to declare the NSDictionary objects (blogPost 1, 2 etc) as properties in our TableViewController header file as we did with the NSArray (*blogPosts - formerly *titles).
Hi Micheal, according to my understanding...
- If we don't define the variables (which could be basic data types (like int, float ) or NSArrays, or dictionaries etc) as properties then we will not be able to access them from outside the class. 2.More over making them as properties will make it easier for the programmer to set and retrieve their values without going through the formal process of defining the setter and getter functions for them.
- Defining the variables in the header file makes them public that is they could be accessed by outside classes and defining them in the implementation file makes them private that is they cannot be accessed outside the class.
- I usually prefer making the variables of a class as properties because first- i can easily access them without setter and getter, and second- they could be easily accessed outside the class as passing there value or getting their value outside the class is a lot easier...
I hope it helps you more in understanding the properties.....
Hi Micheal, I am a little to ios development, but will still try to solve your query.
Since the array will be holding just a single value that is the titles , it is more convenient at this point to declare just a single array of titles which is altogether an array of strings( since titles are nothing but string values). But later in the course you will see that the dictionary is being used to hold all the values (ie title, author, date, url) and those dictionary objects are being stored in an NSMutableArray. An array will more easily hold all the objects( each object being a dictionary) and since it is a NSMutable type , it will be less tedious and more manageable. Consider if we have 1000 posts then creating a property for each and every dictionary object will be a mess!!!
I really hope my answer would be able to solve some of your confusion....