开发者

objective-c how to synchronize two objects between rootViewController and modalViewController

I'm new to OOP and I'm confused about this following line on chapter 6 of head first iphone development:

addDrinkVC.drinkArray = self.drinks

the purpose is to assign the self.drinks NSMutableArray to another NSMuta开发者_如何学运维bleArray in modal viewController addDrinkVC. But why when you added an object into drinkArray in modal view and returned to the rootView and reload the tableView, self.drinks also gets changed? Is it related to the concept of pointer?

Thanks!


Unless drinkArray is declared with @property (copy), the contents of the array are not copied. This does indeed have to do with pointers. Since the array is mutable, and since you are not copying it – only adding a new reference to it – any changes made to either reference will be visible on the other. In other words, there is only one actual array in use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜