When the NSMutableString value changes after writing to an array, the values in the array change as well, should it be? Or how to explain its change?
Here is the code for an example:
NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:10]; NSMutableString *name = [[NSMutableString alloc] init]; [name setString:@"Alice"]; names[0] = name; NSLog(@"%@",names); [name setString:@"0"]; NSLog(@"%@",names); Here is the output of the program:
Alice 0 Although it should be:
Alice Alice When replacing NSMutableString with NSString, outputs as necessary