a function is doing multiply things in blocks. I want to hide hud when a task is done and shows the hud for the next task. but it shows the hud at first and hides it in the end. whats the problem? This is my code:
@IBAction func syncBtn(_ sender: Any) {
let loadingNotification = MBProgressHUD.showAdded(to: view, animated: true)
loadingNotification.mode = MBProgressHUDMode.indeterminate
loadingNotification.label.text = "Syncing with server..."
myAPI.SendInspectResultGetMaterials { (materials, result) in
if result {
MBProgressHUD.hide(for: self.view, animated: true)
let loadingNotification = MBProgressHUD.showAdded(to: self.view, animated: true)
loadingNotification.mode = MBProgressHUDMode.indeterminate
loadingNotification.label.text = "Generating Database..."
self.GenerationTheDatabase(materials: materials!, Completion: { result in
self.myAPI.GetSetVals { (setvals) in
_ = RealmService.shared.deleteAllFromObject(RealmSetVals())
for item in setvals.value {
let newSetVal = RealmSetVals(Id: item.id, ReasonType: item.type, Name: item.name)
_ = RealmService.shared.create(newSetVal)
}
self.myAPI.GetUserInfo(Completion: { (userInfo) in
MBProgressHUD.hide(for: self.view, animated: true)
let aDipach = DispatchQueue.global(qos: .background)
aDipach.async {
DispatchQueue.main.async {
SVProgressHUD.showSuccess(withStatus: "Synced Successfully")
}
}
})
}
})
}
else{
MBProgressHUD.hide(for: self.view, animated: true)
let aDipach = DispatchQueue.global(qos: .background)
aDipach.async {
DispatchQueue.main.async {
SVProgressHUD.showError(withStatus: "Error while syncing")
}
}
}
}
}
I know for using hud I have to use blocks in code and I did it but it doesn't work till the end