需要澄清 addObjectsFromArray 函数

发布于 2024-09-07 22:18:29 字数 620 浏览 0 评论 0原文

我有以下代码(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-09-14 22:18:29

通过保留刚刚填充 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文