I have to send a POST request to a server with Alamofire but need to change the "id" in the body parameters every time that the previous api call has been completed.
Here is what I did so far, but Alamofire makes 3 request, based on the number of ids contained in an array, but it always perform the api call with the same "id" without doing it progressively like: (id:0 then id:1 then id:2 and so on):
func getVirtualCards() {
DispatchQueue.main.async {
for card in self.cardsListId ?? [] {
CardsClient.getVirtualCards(cardId: card.id, completion: { [weak self] result in
switch result {
case .success(let response):
guard let cardInfo = response.cardContext?.cardInfo else {return}
self?.cardsList?.append(cardInfo)
guard let cardList = self?.cardsList else {return}
self?.cardsViewController?.cardsData = cardList
case .failure(let error):
print(error.localizedDescription)
}
})
}
}
}
How can I get it work correctly?
Thanks for your help