Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between _var and self.var

With all this new ARC stuff (which does not fall under NDA…) coming out, it seems like the default for dealing with properties is to set the property without and ivar in the implementation file explicitly until you synthesize it with something like:

@synthesize var = _var;

What's the best practice to use in setting the variable? I know the difference between var and self.var is that self.var is using dot notation and is using the var's setter method.

Is _var just the equivalent of setting it up within the header files like in the good ol' days? Where did that practice of prefacing everything with an underscore come from?

like image 717
SushiGrass Jacob Avatar asked Sep 09 '26 21:09

SushiGrass Jacob


1 Answers

_var is just a different name for the instance variable (presumably so you don't accidentally access directly it when you meant to use an accessor). It doesn't have any special meaning in the language beyond just being a valid ivar name.

like image 173
Chuck Avatar answered Sep 12 '26 10:09

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!