I\'m trying to modify the contents of one pointer using another. I want string2 to point to what string1 points to, so that when I modify string2, it modifies string1. How c
As an alternative to Richard J. Ross III's answer, since they're already pointers — buying you a level of indirection — just make sure that you change what's at the address they're pointing to while leaving it at that address. So, e.g.
NSMutableString *string1 = [[NSMutableString alloc] initWithString:@"hello"];
NSMutableString *string2 = string1;
[string2 setString:@"changed"];
NSLog(@"string1: %@, string2: %@"); // "string1: changed, string2: changed"
It's not really a workable general solution because it goes too much against the flow of normal Cocoa practices, but understanding what's going on with pointers and how they communicate objects is worthwhile.