@ Interface... @ Property (atomicity, writability, memory management) ID name; @ end
Atomicity: nonatomic, atomic default atomic writability: readwrite, readonly default readwrite memory management: Assign, retain, copy default assign default value: because these attributes have default values, therefore, you can specify any attribute or do not specify it at all:
@ Property ID name; // equivalent to the next line: @ property (atomic, readwrite, assign) ID name;
Writability: @ property ID name generates two setter and getter access interfaces.
-(void) setName:(id)name;-(id) name;
Therefore, readonly indicates that only getter functions are generated without setter functions. The default value is that both functions generate memory management. Assign indicates that interfaces do not modify object references at any time; retain indicates that when setter is called, the previous object will be release, and the new object will be retain; When getter is called, retain; copy indicates that the new object will be copied when setter is called, and the previous object will be release; when getter is called, The retain; @ property (assign) ID name; is equivalent
-(void) setName: (id) aName{ self.name = aName;} -(id) name{ return self.name;}
@ Property (retain) ID name; equivalent
-(void) setName: (id) aName{ if ([self.name retainCount > 0]) { [self.name release]; } [aName retain]; self.name = aName;} -(id) name{ [self.name retain]; return self.name;}
@ Property (copy) ID name; equivalent
-(void) setName: (id) aName{ if ([self.name retainCount > 0]) { [self.name release]; } self.name = [copy aName];} -(id) name{ [self.name retain]; return self.name;}
Conclusion: In addition to the assign attribute, the release object must be used; otherwise, the memory will leak! This is too troublesome. Thanks to arc.
Objective-c Property Parsing