oc-@property parameters in memory management

Source: Internet
Author: User
Tags float double

1. Declaration of production get and set methods

2. Generate a simple implementation of get and set methods

/*-(void) Setcar: (Car *) car{

_car = car;

}

-(Car *) car{

return _car;

}

*/

3. If you do not have a member variable of the Fame object, then he will automatically generate a member variable at the beginning of _

@property parameters are divided into 4 categories

/*

1. Parameters related to the Set method memory management

Retain: To generate a set method (Application and object type) that conforms to the memory management principle (only the old value is retain in the setter, the new value is added)

-(void) Setcar: (Car *) car{

if (_car! = car) {

[_car release];//release old value

_car = [Car retain];//retain new value

}

Assign: Direct assignment, (object type, base data type)

Copy: (explained later)

*/

2. Multithreading-related

Nonatomic: Do not generate multithreaded related code, use this can be (more efficient)

Atomic: Generate multithreaded Correlation code (this is not written by default)

In the actual development, as long as the object type of the @property are written below

3. Do you want to generate the set and get methods

ReadWrite: Readable writable property, simultaneous generation of set and get methods

ReadOnly: Read-only property, generating only get methods

4.set parameters associated with the Get method name

Setter: Sets the generated Set method name

Getter: Set the generated Get method name

@property (nonatomic,retain) car * car;

@property (nonatomic,retain) nsstring * name;

@property (nonatomic,assign) int age; int float Double Char

@property (nonatomic,assign) int weight;

@property (nonatomic,assign,readonly) int idcard;

@property (nonatomic,assign,setter = Abc:,getter = zhuanghuimei) int height;

/**

[P abc:100];

int b = [P Zhuanghuimei];

P.height = 100;//[p Abc:10];

NSLog (@ "He%d", p.height);//[p Zhuanghuimei];

P 0

*/

Changing set and get method names is a lot of variables that are used in type bool

@property (nonatomic,assign,setter = Isdeid:,getter = Isdeid) BOOL Isdeid;

Because the one that's automatically generated above is

-(void) Setisdeid: (bool) Isdeid; But previously it was said that the BOOL type is the beginning of is, so this method is used to set the is beginning, as follows:

-(void) Isdeid: (BOOL) Isdeid;

oc-@property parameters in memory management

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.