objective c - What is @synthesize foo = _foo all about? -


Why prefix this underscore in an iOS app?

Sometimes it helps to see what is happening to understand these scenes. Actually when you see it

  @property (nonatomic, retain) Foo * foo;   

In this implementation

  @ synthesize foo = _foo;   

This is syntax for the following, which means that the compiler basically generates this code for you

  Foo * foo = nil; - (Foo *) Afu {Returns _Foo; } - (zero) setFoo: (Foo *) val {if (_foo! = Val) {[_foo release]; _fu = [VAL intact]; }}   

In this way, when you mention the public property, you hit it through the generated items of self.foo and if You want to refer to this example that you can mention the _foo variable inside your class. XCode was easy to be confused between two before four. You can do something like

  self.foo = foo1; Foo = foo2;   

It was absolutely legal and could cause problems at some levels. The second line does not use the accessor, so foo2 will not be retained, which it can already be picked up by garbage collection. Even worse, the second line does not use the accelerator, which will release any previous value, which means the memory leak

So in summary, the new technology makes you the property maker and the setter for you to specify the name used for the frequency variable, to use for encapsulation.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -