我有以下代码(items和itemsCopy都是NSMutableArray):
//DO: populate items w/ 30 elements
[self.itemsCopy addObjectsFromArray:self.items];
//DO: remove all elements in items
结果
Begin Pass 1:
itemsCopy = 0
items = 30
End Pass 1:
itemsCopy = 30
items = 0
Begin Pass 2:
itemsCopy = 0
items = 30
End Pass 2:
itemsCopy = 30
items = 0
如何不断地将物品附加到itemsCopy的末尾?我希望这个场景看起来像这样:
Begin Pass 1:
itemsCopy = 0
items = 30
End Pass 1:
itemsCopy = 30;
items = 0;
Begin Pass 2:
itemsCopy = 30
items = 30
End Pass 2:
itemsCopy = 60
items = 0
答案 0 :(得分:3)
通过保留相同的数组,您只需填写itemsCopy
属性。无论你使用什么方法,它显然都被重置为一个空数组。