1: @property @synthesize properties (similar to get set in Java)
The original implementation of the above class is this:#import @interfacePhoto:nsobject {nsstring*caption; NSString*photographer; } -(nsstring*) caption; -(nsstring*) photographer; - (void) Setcaption: (nsstring*) input; - (void) Setphotographer: (nsstring*) input; @endIf the property is used to achieve this:#import @interfacePhoto:nsobject {nsstring*caption; NSString*photographer; } @property (retain) NSString*caption; @property (retain) NSString*photographer; @end@property's objective .-C to declare the compiler directive for the property. Inside the parentheses."retain"indicates the object that the setter needs to retain input. The other parts of this line specify the type and name of the property. Let's take a look at the implementation of this class:#import "Photo.h" @implementationPhoto@synthesizecaption; @synthesizephotographer; - (void) Dealloc {[caption release]; [Photographer release]; [Super Dealloc]; } @end@synthesize instructions are automatically generated by our setters and getters. So we just need to implement the Dealloc method of the class. Accessors are generated only when they are not. So you can be confident to use @synthesize to specify properties. And you can freely implement your own getter and setter. The compiler will find out for itself which method is not. View Code
iOS Basic Learning II