Objective-C: 12_copy

Source: Internet
Author: User

A copy of an object can be created using the copy or nutablecopy method. The original object is not affected when the copy is modified. Copy : Must be implemented first Nscopying Protocol , Creating an immutable copy (Such as nsstring, nsarray, and nsdictionary) Mutablecopy : Must be implemented first Nsmutablecopying Protocol , A mutable copy is created. (Such as nsmutablestring, nsmutablearray, and nsmutable) Deep copy: the source object and copy point to two different objects. The Reference Counter of the object remains unchanged, and the copy counter is set to 1 Copy: pointer copy. The source object and copy point to the same object. The Reference Counter of the object is + 1, which is equivalent to a retain operation. Only the immutable object that creates an immutable copy is the shortest copy. Mutablecopy is also a deep copy. Nsstring * string = [[nsstring alloc] initwithformat: @ "Age is % d", 10]; nsmutablestring * STR = [String mutablecopy]; Copy generates an immutable copy. Because the source object itself is immutable, copy directly returns the source object for the sake of performance. The source object counter will be + 1 Nsstring * STR = [String Copy];

Objective-C: 12_copy

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.