Attribute characteristics in OC

Source: Internet
Author: User

At the beginning of the process of learning OC, has been the declaration after the return value of the attribute characteristics do not understand what meaning, today specially found a bit of information, thoroughly understand the meaning of it.

The attribute features in OC mainly include Assign,copy,retain, the three main, and the Readonly,readwrite. In addition, Atomic and nonatomic; and Strong,weak.

Assign is primarily a simple assignment for the underlying type data and the C data type, and it does not call the index counter (retain count).

Retain primarily refers to the invocation of objects in OC, the assignment of objects in OC (primarily for NSObject and its subclasses), the need to call the index counter (retain count) for +1 operations, open up new memory space, and release operations after the new values are assigned.

Copy refers to the use of a copy of the object, the count of the index counter remains at 1, it just creates a new pointer for the object, pointing to the object at the corresponding location in memory, and does not open up new memory space (at this point, replication is shallow copy).

ReadOnly is to generate only getter methods, not setter methods, which are read-only storage.

ReadWrite is the default property and will generate getter and setter methods with no additional parameters.

Assign is an atomic access, and if more than one thread calls the setter method, it does not appear before one thread calls the setter to finish, and another thread starts calling the setter, which can be said to lock the property.

Nonassign non-atomic access, no synchronization and multithreading, no locking, when there are multiple threads, there will be problems, but this relatively improved performance.

Attribute characteristics in OC

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.