IOS @ Property

Source: Internet
Author: User

@ Property (nonatomic, assign) nsstring * title;
What are the differences between assign, copy, and retain?

Assign: simple value assignment without changing the index count (reference counting ).
Copy: Create an object with an index count of 1 and release the old object.
Retain: Release the old object, assign the value of the old object to the input object, and increase the index count of the input object to 1.
The actual retain syntax is:

-(Void) setname :( nsstring *) newname {
If (name! = Newname ){
[Name Release];
Name = [newname retain];
// Name's retain count has been bumped up by 1
}
}
The following is the most important thing:

? If you don't know how to use them, then->

Use assign: for basic data types (nsinteger, cgfloat) and C data types (INT, float, double, Char, etc)
Use copy: To nsstring
Use retain: for other nsobject and its subclass
Nonatomic Keyword:

Atomic is a thread protection technology used by objc. It basically prevents reading data by another thread when the write is not completed, resulting in data errors. This mechanism consumes system resources. Therefore, nonatomic is a good choice for small devices such as the iPhone, if multi-thread communication programming is not used.

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.