So I need an Alert to present itself before some UI updates happen. Thus, this is what I did:
let alert = UIAlertController(title: "Loading!" , message: "Your data is loading", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(ok)
ok.isEnabled = false
let queue = OperationQueue()
queue.qualityOfService = .userInteractive
queue.addOperation {
if (UserDefaults.standard.integer(forKey: "numAllowed") == 3){ //it only presents depending on a setting
OperationQueue.main.addOperation {
self.present(alert, animated: true, completion: {print ("it presented")})
}
}
OperationQueue.main.addOperation{
var newValues = URLResourceValues()
newValues.isHidden = true
try! cell.videoURL?.setResourceValues(newValues)
try! cell.urlJpg?.setResourceValues(newValues)
self.refresh()
self.tableView.reloadSections([0], with: .fade)
self.refresh()
self.tableView.reloadSections([0], with: .fade)
ok.isEnabled = true
}
}This has worked all but two times. The times it doesn't work what happens is it'll run lines 16-26, than present Alert at line 12. It doesn't make sense to me why!