Friday 15 February 2013

objective c - @synthesize behind the scenes -


When we make an asset and define a synthesize for it, the compiler automatically builds the getters and setters methods Is not it?

Now, if I execute this command:

  @property (nonatomic) int value; @ Synthesis value; Value = 50;  

What happens:

Is the value '50' in the compiler property?

  Properties (non-manual) int value; // The value stored here is 50!  

or the compiler creates a variable behind such a landscape named property:

  Interface myClass: NSObject {int value; // The value stored here is 50! }  

What really happens and the options listed above are correct?

This is probably semantic, but for properties, @ synthesis is not necessary anymore The compiler does the automatic

But to answer your question, the compiler creates an example variable to store the value of the property.

  @property (nonatomic, assign) NSInteger value; // an example variable NSInteger _value; Will be built in the interface.  

You can use the instance variable in your own code, if you need to access it without leaving the property, it is normal to override a setter, such as: < / P>

  - (zero) set value: (NSInteger) value {_value = value; // custom code}  

No comments:

Post a Comment