Ios-property Property Introduction

Source: Internet
Author: User

An explanation of Ios property properties

property is an attribute that is added by Objective-c to automatically generate setter and Getter methods. It can not only help us to manage the memory there are some other special functions such as multithreading control, memory management.

@property keywords are divided into three categories: Atomicity, operability, memory management. Typically, the default is atomic, ReadWrite, assign, so its keywords can be set to a maximum of three.

Atomic nature:

1) atomic:atomic refers to atomic operations, meaning that only one thread can access instance variables at the same time and can be used in multithreaded operations to ensure thread safety.

2) Nonatomic:nonatomic is the opposite of atomic, which means that non-atomic operations can be accessed concurrently by multiple threads. It is faster than atomic, can not ensure thread safety, and is generally used in single threaded.

operability:

1) ReadWrite: Indicates that both read and write operations can be performed (i.e., having getter and setter methods).

2) ReadOnly: Indicates that only getter methods do not have setter methods.

Memory Management:

1) assign:assign is used for value types, such as int, float, double, nsinteger, cgfloat, etc., to represent pure replication. In addition delegate general with assign

2) Retain: A reference count plus 1 for the incoming object is required in the setter method. is to take ownership of the incoming object so that it will not be freed.

Retain declaring instance variable setter methods:

-(void) Setretainstr: (NSString *) Retainstr {

if (_RETAINSTR!=RETAINSTR) {

[_retainstr release];

_retainstr=[retainstr retain];

}

}

3) Strong:strong is an optional alternative to the retain. As retain means, the instance variable has ownership of the incoming object, which is a strong reference (strong).

4) Weak: In the setter method, the incoming object does not have a reference counter plus 1 operation that does not take ownership of the incoming object. When the object is released, the weak declares the instance variable of the township nil.

5) Copy:copy is a deep copy, which refers to the instance variable ownership of the copy of the incoming object. The original object of the modified copy does not change.

Ios-property Property Introduction

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.