I’m starting with obj-c and there’s a few things I don’t get.
First of is I (oh I’m coming from an AS3 coding perspective) thought that if you wanted to have a variable in your class, you needed to declare it first in the header with the @property operator, and then @synthesize in the .m file, and also you had to declare the method in the header as well, but I’ve come across situations where variables are just defined in the methods in the .m file, without any declaring anywhere, and the same for the methods, methods that are just written straight into the .m file with no declaring and they work fine.
So what’s the point of the @property/@synthesize for variables and declaring the methods in the header files? it is all to do with scope?
What you are talking about is not referred to the declaration of a variable but to expose it from outside of the class through a getter and a setter.
The @property/@synthesize are just a shortcut to automatically create two methods which are
- (void) [class setVariable:(type)var]- (type) [class variable]that can set and get the variable from other classes.
Not every variable needs to be set or got from outside the class.