When you use a variable from .h-file, you'd say self.progress
If you use a variable from the .m-file, it's _levels
There is no difference. self.progress
and _progress
and self.levels
and _levels
are all perfectly functional.
However, the _
syntax is a tiny bit faster and the self.
syntax is the proper way to do it except in a few cases where it's not. There are times when using _
will cause serious problems that are solved by using self.
. And there are times when self.
will cause problems.
Basically _
is accessing the raw memory address directly, and self.
is accessing it "properly" using the objective-c language.
The difference between declaring a variable in *.m vs *.h is that the one in *.m is hidden, so nothing else in your source code can see that it exists. It is there but you will get a compiler warning that it doesn't exist. When it compiles it will work though, because really it does exist.
Basically declaring variables in *.m is a way of saying "this thing is here but I don't want anything outside this file to ever use it". It's purely cosmetic, has no impact on the how the app functions.
As a new Obj-C programmer, you should always use self.levels
. Any time you see sample code using _levels
I would change it to self.levels
. If you run into problems... ask here to see if you've found a case where _levels
should be used.