I'm new to swift and this week I came across a problem that is already making me pluck my hair!
What happens is the following, divided in my application in several classes to leave my code more "clean" and in this wave I decided to divide some functions into classes by the project, but so far so good.
The problem is how Swift handles the execution queues, leaving behind everything that is not in my ViewController, which is hindering me.
I'll show you some of the code so you can better extend what I'm saying.
The function of the button of my ViewController:
@IBAction func btnLogin(_ sender: UIButton) {
//The line that the Swift "skips"
let dadosAlunoWS = FadbaWS.buscaAluno(matricula: MatriculaTbox.text!, senha: SenhaTbox.text!, token: "TOKEN")
//'dadosAlunoWS' aways empty because 'FadbaWS.buscaAluno'
//is only performed at the end of 'btnLogin'
if dadosAlunoWS.sucesso && dadosAlunoWS.usuarioEncontrado{
print(dadosAlunoWS.name)
}else{
//Error on request
}
}
I know the concept of parallelism and concurrency and researching I was able to realize that it is Swift's native to prioritize the interface, which makes everything fluid, but my problem is that my 'FadbaWS.buscaAluno' function is never executed and thus never returns a valid value .
How do I give priority so that my code only proceeds after executing this function?
How to handle the DispatchQueue in Swift?
Right now, grateful!