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 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.