grand-central-dispatch

Working with nested async Firebase calls SwiftUI

五迷三道 提交于 2020-07-10 05:54:10
问题 I am relatively new to async functions and I understand that the firebase getDocument and getDocuments calls are async. I would like both of these calls to finish before I move on to what I was doing in the code. I've been trying to implement this with dispatch groups, but have been unsuccessful thus far. I have code like the following: let myGroup = DispatchGroup() self.errorMessage = "" let usersRef = self.db.collection("Users").document("Users").collection("Users") if self.test == false {

Remove initiallyInactive queue

谁说我不能喝 提交于 2020-06-28 05:12:55
问题 I have array of photos that needs to be downloaded, but download function can download only one photo at a time. I neeed to make sure that download function is completed before I call it for other photo. I create .initialyInactive DispatchQueue and queue is activated in completion block of download function. This is woking, and photos are downloaded, but my question is how to cancel download process? Can I somehow to remove not activated queues? My code logic looks something like this.. func

DispatchQueue : Cannot be called with asCopy = NO on non-main thread

不问归期 提交于 2020-06-24 10:58:28
问题 I am presenting the UIAlertController on the main thread as : class HelperMethodClass: NSObject { class func showAlertMessage(message:String, viewController: UIViewController) { let alertMessage = UIAlertController(title: "", message: message, preferredStyle: .alert) let cancelAction = UIAlertAction(title: "Ok", style: .cancel) alertMessage.addAction(cancelAction) DispatchQueue.main.async { viewController.present(alertMessage, animated: true, completion: nil) } } } And I am calling the method

Swift: Simple DispatchQueue does not run & notify correctly

核能气质少年 提交于 2020-05-29 16:59:25
问题 What i am doing wrong? At playground it runs as it should. But as soon as i deploy it on iOS simulator it returns the wrong sequence. @objc func buttonTapped(){ let group = DispatchGroup() let dispatchQueue = DispatchQueue.global(qos: .default) for i in 1...4 { group.enter() dispatchQueue.async { print("🔹 \(i)") } group.leave() } for i in 1...4 { group.enter() dispatchQueue.async { print("❌ \(i)") } group.leave() } group.notify(queue: DispatchQueue.main) { print("jobs done by group") } }