Quote:
Originally Posted by RLScott
No, it should not change FirstClassString, and here is why.
Both FirstClassString and SecondClassString are pointers to NSString objects. At the time when you do
Code:
[secondClass setSecondClassString:firstClassString];
This makes both pointers point at the same NSString. The two pointers are still distinct pointers. Neither pointer points at the other pointer. They just both point at the same object. Then when you do
Code:
[self setSecondClassString:@"this should change the firstClassString, no?"];
That makes SecondClassString point somewhere new. It does not change the object that it was pointing at. And FirstClassString is still pointing at the old object. So nothing changes, as far as FirstClassString is concerned.
|
Thanks for the explanation but then why does it work with NSMutableArrays? For example,
NSMutableArray firstClassArray;
NSMutableArray secondClassArray;
...
...
...
[secondClass setSecondClassArray:firstClassArray];
...
then in the second class, you do something like this:
[secondClassArray insertObject:anObject atIndex:0];
...
in my first class, the firstClassArray @ index 0 will get changed to anObject.
Maybe, I am overthinking stuff but if you can show me how I can pass NSString from one view controller to another VC, change the value, and then pass back that value, I would appreciate it. Right now, I'm using the NSMutableArray because the NSString doesn't change in the first class.
Thanks!