I have a simple question. If I am declaring NSString (ref type) as shown below:
NSString *johnsMoney = @\"200\";
NSString *marysMoney = johnsMoney;
suppose the string :
@"200" pointer address : 0xeeff
@"100" pointer address : 0xeeaa
so ,your code may change like these:
NSString *johnsMoney = @"200";
(johnsMoney = 0xeeff)
NSString *marysMoney = johnsMoney;
(marysMoney = 0xeeff)
johnsMoney = @"100";
(johnsMoney = 0xeeaa)
(marysMoney = 0xeeff)
marysMoney pointer address not changed,but johnsMoney pointer address changed.
As the same:
suppose the object :
dog1 pointer address : 0xeeff
so ,your code may change like these:
Dog *dog1 = [[Dog alloc] init];
(dog1 pointer address: 0xeeff)
dog1.name = @"Dog 1";
Dog *dog2 = dog1;
(dog2 pointer address: 0xeeff)
dog1.name = @"Dog 3";
(dog1 pointer address still: 0xeeff)
(dog2 pointer address still: 0xeeff)
As they all point to the same address,they both changed。