Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ycyclop

macrumors newbie
Original poster
Jun 23, 2009
1
0
Hi all,
I'm new to this objective C and I thought I understood what I was doing, but apparently not. here is a simplified sample of my problem:

I have two objects:

MyObj* obj1 = [[MyObj alloc] initWithMyData:X];
MyObj* obj2 = [[MyObj alloc] initWithMyData:Y];

I wanted to switch the content of the two items with the following simple code:

MyObj* temp = obj1;
obj1 = obj2;
obj2 = temp;

so when I look at the address, obj1 now hold the address of what was previously obj2 and obj2 hold the address of obj1
looks like what I wanted right? NO
the data inside obj1 is the same data as before. and same for obj2:

obj1.data is still X as initilized with but address of what was obj2
obj2.data is still Y as initilized with but address of what was obj1

so how come when I replaced the pointers the data stayed the same?

Thank you in advance for any help
 
Are you sure you didn't make a mistake in looking at the content of these objects?

Maybe you should post a concrete example with the actual source code showing that you found "X" in one case and "Y" in the other. For example print the value X in one object before and after the swap.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.