0
Hello, I’m new to Swift and this week I came across a problem that is already making me pull my hair out!
What happens is this, I divided in my application in several classes to make my code more "tidy" 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, putting everything that’s not in my Viewcontroller in the background, which is getting in my way.
I’m going to show you a little bit of code so you can extend what I’m saying better
The function of my Viewcontroller button:
@IBAction func btnLogin(_ sender: UIButton) {
//Eis a linha que o swift "pula"
let dadosAlunoWS = FadbaWS.buscaAluno(matricula: MatriculaTbox.text!, senha: SenhaTbox.text!, token: "TOKEN")
//'dadosAlunoWS' será sempre vazio porque 'FadbaWS.buscaAluno'
//só é executada ao fim de 'btnLogin'
if dadosAlunoWS.sucesso && dadosAlunoWS.usuarioEncontrado{
print(dadosAlunoWS.nome)
}else{
//Erro na requisição
}
}
I know the concept of parallelism and competition and researching I could realize that it is native of Swift to give priority to interface, which makes everything fluid, but my problem is that my function 'Fadbaws.search' is never executed and so never returns a valid value.
How to prioritize my code only to continue after performing this function?
How to deal with Dispatchqueue on Swift?
From now on, thank you!
You will need to use a callback as a parameter in your method searchAluno. I suggest to give a search on callback on swift.
– Leonardo Cesar Teixeira