需要澄清 addObjectsFromArray 函数
我有以下代码(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
I have the following code (both items and itemsCopy are NSMutableArray's):
//DO: populate items w/ 30 elements
[self.itemsCopy addObjectsFromArray:self.items];
//DO: remove all elements in items
Results
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
How can I constantly append items to the end of itemsCopy? I would like the scenario to look like this:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过保留刚刚填充
itemsCopy
属性的相同数组。无论您使用什么方法,它显然都会被重置为空数组。By keeping the same array you just filled in the
itemsCopy
property. It's clearly being reset to an empty array with whatever method you're using.