About the copy method of the object

Use the copy method to assign values, which are shallow copies. The memory address is not re-opened, but the object is pointed to the same memory address.

Using the mutableCopy method to assign values ​​is a deep copy, which will re-open a memory address.

NSArray *arr1 = @[@"123213"];

NSArray *arr2 = arr1.copy;

NSArray *arr3 = arr1.mutableCopy;

NSMutableArray *arr4 = arr1.copy;

NSMutableArray *arr5 = arr1.mutableCopy;

NSLog(@"%p",arr1);
NSLog(@"%p",arr2);
NSLog(@"%p",arr3);
NSLog(@"%p",arr4);
NSLog(@"%p",arr5);

result:

2019-06-01 11:54:57.222852+0800 test[5917:89508] 0x600001e41ad0

2019-06-01 11:54:57.223034+0800 test[5917:89508] 0x600001e41ad0

2019-06-01 11:54:57.223458+0800 test[5917:89508] 0x60000121ad00

2019-06-01 11:54:57.223799+0800 test[5917:89508] 0x600001e41ad0

2019-06-01 11:54:57.224152+0800 test[5917:89508] 0x60000121b960

Guess you like

Origin blog.csdn.net/qq_31709953/article/details/99357105