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.