Objective-c Property Parsing

Source: Internet
Author: User

 

@ 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.