Differences between Copy and MutableCopy: copymutablecopy

Source: Internet
Author: User

Differences between Copy and MutableCopy: copymutablecopy

NSString * string = @ "origion"; NSString * stringCopy = [string copy]; NSMutableString * stringMCopy = [string mutableCopy]; [stringMCopy appendString :@"!! "];

Note the following points in the above Code:

1. retainCount is invalid for constants, and a number is a large number. It is correct for memory objects on the stack and is invalid for Constants on the stack.

2. copy refers to the replication pointer.

3. mutableCopy is a deep copy that copies the object to the new memory space.

4. mutableCopy (NSMutableString)

NSMutableString * string = [NSMutableString stringWithString: @ "origion"]; NSMutableString * stringCopy = [string copy]; [stringCopy appendString :@"!! "]; // ERROR NSMutableString * stringMCopy = [string mutableCopy]; [stringMCopy appendString :@"!! "];

Note the following points in the above Code:

1. Whether the copy object is Mutable (NSMutableString) or non-Mutable (NSString), all the copied objects are non-Mutable (NSString ). So it will crash.

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.