I’ve been running though some tutorials and often times I will see something like this.
in the .h
UIButton *_loginButton;
@property (retain) IBOutlet UIButton *loginButton;
Then in the .m it will be something like…
@synthesize loginButton = _loginButton;
So my question is what benefit does putting an _ before do? or why is it common practice? and lastly should I be doing this as well?
It’s a convention that people sometimes use to denote private instance variables, or to separate instance variables from properties. You’ll sometimes see names with a leading underscore used for private functions or methods. As far as I know, Apple reserves that convention for its own use and recommends that you not use it in order to avoid name collisions. For that reason, you’ll sometimes also see names that have a trailing underscore instead of a leading one, i.e.
foo_instead of_foo.