Assign, nonatomic, copy, strong and other indicators of the role of the collation

Source: Internet
Author: User

When we use @property to define attributes, we find that some extra indicators are often added between the @property keyword and the type, and this article organizes these indicators.

Assign

The indicator specifies that the property is simply assigned a value and does not change the reference count for the attached value. This indicator is mainly applicable to basic types such as Nsinteger, as well as various C data types such as short,float,double, structs, and so on.

Atomic (nonatomic):

Specifies whether the access method of the composition is an atomic operation. Atomic manipulation refers to whether thread-safe, if the use of atomic, then the method of access to the composition is thread-safe, that is, when a thread enters the method body of the access method, other threads can not access the access method, to ensure the integrity of the data, atomic is the default value. But atomic's thread safety also causes performance degradation, so nonatomic is used in most single-threaded environments to improve access performance.

Copy

With this indicator, when a member variable is assigned using the setter method, the assigned object is assigned a copy and the copy is assigned to the member variable. The copy indicator will reduce the reference count of the object referenced by the original member variable by one.

Strong (weak):

The strong indicator specifies that the property holds a strong reference to the assigned object, and the weak indicator specifies that the property holds a weak reference to the assigned object. A strong reference means that the object is not automatically reclaimed as long as it points to an assigned object. A weak reference is a time when the reference points to the object being assigned, and the object may be recycled.

Assign, nonatomic, copy, strong and other indicators of the role of the collation

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.