Delay in For loop

I am creating a simple card game (Set) in SwiftUI. I have a button that will deal X new cards when tapped. Currently, it makes all cards show up at once. I was wondering how I could make them come out one at a time.

Deal works by appending a new card to a Deck array in the model. ContentView displays each card in the grid.


Code Block
func deal(_ numberOfCards: Int) {
withAnimation(Animation.easeInOut(duration: 1)) {
viewModel.deal()
}
for _ in 1..<numberOfCards {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
withAnimation(.easeInOut) {
viewModel.deal()
}
}
}
}

Answered by tbraun1551 in 617319022
Solved it. Realized it should be 0.7 * i
Accepted Answer
Solved it. Realized it should be 0.7 * i
Delay in For loop
 
 
Q