Alamofire异步请求在for循环中无序发生

编程入门 行业动态 更新时间:2024-10-11 23:17:10
本文介绍了Alamofire异步请求在for循环中无序发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Swift中遇到了Alamofire异步请求这个奇怪的问题。这是我想要做的伪代码。

I'm having this strange issue with Alamofire asynchronous requests in Swift. Here is the pseudocode for what I am trying to do.

for each email: GET request to grab first_name for email add first_name to an array

问题是结束数组乱序。当应该是[用户3,用户1,用户2]时,它是[用户3,用户2,用户1]。我已经用Postman测试了我的后端功能,一切正常,所以很困惑究竟是什么问题。任何洞察可能发生的事情或为什么我没有得到正确的结果。

The issue is that the end array is out of order. When it should be [User 3, User 1, User 2] it is instead [User 3, User 2, User 1]. I've tested my backend funtions with Postman and everything works so am confused as to what exactly is the problem. Any insight into what might be happening or why I am not getting the correct result.

推荐答案

异步调用就是这样。 异步。

Asynchronous calls are just that. Asynchronous.

无论启动顺序如何,您都无法保证哪一个会先完成。

You cannot guarantee which one will finish first regardless of the order in which they were started.

更多推荐

Alamofire异步请求在for循环中无序发生

本文发布于:2023-11-26 02:03:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发生   Alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!