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 Objective-C Basics (Retired) Introduction to Objective-C Introducing @property

Taylor Mahony
Taylor Mahony
5,814 Points

Why use instances, setters and getters at all?

So I just watched one video about instance variables, setters and getters, and then another about properties in which you blew away most of the code and yet it still worked. My question is- will we ever use instance variables, setters and getters? Or should we not even worry about commuting them to memory if properties are the way to go?

3 Answers

The reason is because sometimes you want to intercept what is being passed in during a getter or a setter and do something with it. This could be checking to see if the value is > a default max value which allows you to throw an error and not actually set the variable. Or even using 2 variables to set a 3rd variable. Properties are only a convenience if you don't have to do anything with the data at the time of set or get.