Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what @synthesize variable = _variable will do?

I have seen code like that in the Application delegate in iPhone project for example.

what is the variable with the underscore means? can I use it as setter and getter for the variable?

also when releasing the variable should I use:

  [variable release]; 

or

 [_variable release]; 

Thanks.

like image 805
Samssom Avatar asked Dec 03 '25 21:12

Samssom


1 Answers

In some coding conventions the underscore before instance variables is used to be able to quickly differentiate them from other variables. It also helps avoid naming conflicts with local variables in methods and subclass methods.

@synthesize variable = _variable 

Creates a setter and getter that set/get the variable you set it to in this case _variable. So outside access uses code like object.variable which is really just returning _variable. however the class usually uses the _variable internally.

like image 161
Justin Meiners Avatar answered Dec 06 '25 15:12

Justin Meiners



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!