按一定顺序将对象添加到数组中?

发布于 2025-01-02 12:07:34 字数 119 浏览 1 评论 0原文

我有 4 个带有完成块的异步网络请求。完成后,我希望将它们添加到主 NSMutableArray 中,这是请求发送的顺序,而不是接收的顺序(因为这可能不同)。我在发送请求时设置了一个标签,这样我就可以在完成块中使用这个标签。

I have a 4 async network requests with a completion block. Upon completion, i want them to be added to a master NSMutableArray is the order that the requests were sent, but not the order they were received (as this may be different). I have a tag that I set when sending the request so I can use this tag in the completion block.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

半步萧音过轻尘 2025-01-09 12:07:34

最初用四个 NSNull 填充数组。在处理程序中,[yourArray ReplaceObjectAtIndex:tag withObject:responseObject]

Fill the array with four NSNulls initially. In the handler, [yourArray replaceObjectAtIndex:tag withObject:responseObject].

萌辣 2025-01-09 12:07:34

我假设您不知道每个请求将返回多少个元素,因此您必须暂时存储所有四个结果集,直到所有四个请求完成。 (一个由标签作为键的 NSMutableDictionary 是有意义的。)然后,您可以迭代字典的键并以正确的顺序将这些 objectForKeys (数组)附加到可变数组中。

I assume you don't know how many elements each request will return, so you'll have to store all four of your result sets temporarily until all four requests are finished. (An NSMutableDictionary, keyed by the tag would make sense.) Then, you can iterate through the dictionary's keys and append those objectForKeys (arrays) to your mutable array in the correct order.

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