Alamofire Asynchronous requests happening out of order in for loop

梦想与她 提交于 2019-12-04 06:12:32

问题


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

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.


回答1:


Asynchronous calls are just that. Asynchronous.

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



来源:https://stackoverflow.com/questions/34612871/alamofire-asynchronous-requests-happening-out-of-order-in-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!