Hi,
I have this code that I need to run in the exact line order, but I can't figure out how to do it.
Things I have tried:
DispatchQueue Aysnc
completion handler functions
Code:
I have this code that I need to run in the exact line order, but I can't figure out how to do it.
Things I have tried:
DispatchQueue Aysnc
completion handler functions
Code:
Code Block let pickedCat = Int.random(in: 1...4) //print("picked cat: \(pickedCat)") if pickedCat == 1 { getRandomJokes() randomJoke.text = "Random Joke: \(self.DadJokes)" //print("Random Joke: \(self.DadJokes)") }else if pickedCat == 2 { getAssistantJokes() randomJoke.text = "Random Joke: \(self.AssistantJokes)" //print("Random Joke: \(self.AssistantJokes)") }else if pickedCat == 3 { getKnockKnockJokes() randomJoke.text = "Random Joke: \(self.KnockKnockJokes)" //print("Random Joke: \(self.KnockKnockJokes)") }else if pickedCat == 4 { getRandomJokes() randomJoke.text = "Random Joke: \(self.RandomJokes)" //print("Random Joke: \(self.RandomJokes)") } if randomJoke.text == "Random Joke: " { randomJoke.text = "Random Joke: Failed to connect to server" }
I figured out that for my case, I can just call it and then wait 0.6 seconds and call it again. To wait blank seconds use (replace 0.6 with the wanted amount):
Code Block DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) { // Put your code which should be executed with a delay here }