Objective-C Runtime Programming Guide: Declared Properties
@property
declares the getter and the setter methods for the public property you want to implement. For example this property declaration:
@property float value;
is equivalent to:
- (float)value;
- (void)setValue:(float)newValue;
@synthesize
provides default implementation for these two accessors.
Update: The above explains what these two do. It does not explain what their purpose is. :-)
@property
adds a member to the public interface that acts as a data variable to your class clients, but is read and written using methods. This gives you better control over the data that is exchanged between the client and your code, for example you can do extended validation on the values your code is given.
@synthesize
allows you to not explicitly write the code that will be called by the client and actually treat the property as a data variable yourself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…