Shallow Versus Deep Copying
Program 18.1 fills the elements of dataArray with immutable strings. (Recall that constant string objects are immutable.) In Program 18.2, you fill it with mutable strings instead so that you can change one of the strings in the array. Take a look at Program 18.2 and see whether you understand its output.
Program 18.2
#import <Foundation/Foundation.h>int main (int argc, char * argv[]){ @autoreleasepool { NSMutableArray *dataArray = [NSMutableArray arrayWithObjects: [NSMutableString stringWithString: @"one"], [NSMutableString stringWithString: @"two"], [NSMutableString stringWithString: @"three"], nil ]; NSMutableArray *dataArray2; NSMutableString *mStr; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access