I just wanted to know if it is necessary to declare a property for every private variable I create in my Xcode projects. If it is, can someone explain me the reason? Thanks =)
Asked
Active
Viewed 93 times
0
-
follow http://stackoverflow.com/a/3571587/1294448 it has good example – Bishal Ghimire Sep 03 '13 at 18:44
-
Properties aren't required. Period. They are 100% optional for both public and private values. – rmaddy Sep 03 '13 at 18:48
1 Answers
1
Properties are useful if you want to add custom get-and-set logic for your variables. They typically are used more for public variables. There are certainly cases when you may want to also use them for private variables, but it is not "necessary".

Kevin DiTraglia
- 25,746
- 19
- 92
- 138
-
You should add that the alternative is to use an instance variable. Used to be that went without saying, since you had to declare the instance var for each property (so just omitting the @property statement gave you the instance var), but now declaring a property implicitly defines the instance var. – Hot Licks Sep 03 '13 at 18:48
-
-
2@Pétur Yes, but 1. that breaks encapsulation and 2. it's another question. – Nikolai Ruhe Sep 03 '13 at 19:08