The difference and use of IOS development property,strong,weak,retain,assign,copy,nomatic

Source: Internet
Author: User
Tags shallow copy

In the 1:ARC environment, strong instead of retain.weak instead of Assign,xcode 4.2 (iOS sdk4.3 and the following versions) and previous versions use Retain and assign, which do not support arc. Xcode 4.3 (iOS5 and above) has an arc and starts using Strong and weak2:weak: In the ARC environment, all weak pointers to this object will be set to nil. This t feature is useful, and it is believed that many developers have been plagued by the exc_bad_access of pointers to objects that have been disposed of, and that after using arc, either strong or weak type pointers will no longer point to an object that has been destroyed. It fundamentally solves the crash caused by accidental release. 3:assign function: Simple assignment, does not change the reference count, for the underlying data type (such as nsinteger,cgfloat) and C data type (int, float, double, char, etc.) for the simple data type assign: For non-pointer variables. For
Underlying data types (such as Nsinteger) and C data types (int, float, double, char, etc.), plus ID
Such as:
@property (nonatomic, assign) int number;
@property (nonatomic, assign) ID classname;//id must be used assign
Anyway, remember: the front does not need to add "*" To use assign bar

4:copy: Create an object with an index count of 1 and then release the effect of the old object 5:strong: In an ARC environment, the object will not be destroyed as long as an object is pointed to by a strong pointer. If the object is not pointed to by any strong pointer, it will be destroyed. By default, all instance variables and local variables are of type strong. It can be said that the strong type of the pointer in the behavior with non-arc under the retain is more similar
6:retain: In the non-arc era, you need to retain an object that you want to keep, which is not required in the ARC environment. Now the only thing to do is to point to the object with a pointer, and as long as the pointer is not reset to NULL, the object will always be on the heap. When the pointer points to the new value, the original object will be release once. This is useful for instance variables, sunthesize variables, or local variables.


Assign: Simple assignment, do not change the index count (Reference counting) to the underlying data class copy: Create an object with an index count of 1, and then release the old object. For Nsstringretain: Releases the old object, assigns the value of the old object to the input object, and then increases the index count of the input object to 1, to the other nsobject and its subclasses
The difference between weak and strong:
the difference between weak and strong is that when an object no longer has a strong type pointer pointing to it, it is released even if there is a weak pointer to it. Once the last strong pointer is left, the object will be released and all remaining weak pointers will be cleared.
The difference between copy and retain:
copy is actually creating an identical object, while retain is not, copy is a copy of the content, retain is a pointer copy, copy is a copy of the content, for like NSString, it is true, If the copy is Nsarray then just copy the pointer to the corresponding element in the array. This is called "shallow copy".
The difference between __block and __weak modifiers
__block can be used in either ARC or MRC mode, can be decorated with objects, and can also be decorated with basic data types. __weak can only be used in Arc mode, can only be decorated with objects (nsstring), and cannot be decorated with basic data types (int). The __block object can be re-assigned in the block, __weak not.

The difference and use of IOS development property,strong,weak,retain,assign,copy,nomatic

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.