0

I'm building a Mac Command line tool in XCode 9.4 using Swift 4.2.

I've to save some data for future use in a background thread using GCD like the code below.

let background = DispatchQueue.global(qos: .background)
background.async { [unowned self] in
    self.saveData(of: self.user, to: "user details")
}

This works well and saves the user data when the application is running for sometime after starting the background thread. But sometimes, the user may exit the application while the background saving process is going on. How do I make the tool complete the saving process and then exit?

teja_D
  • 383
  • 3
  • 18
imthath
  • 1,353
  • 1
  • 13
  • 35
  • See https://stackoverflow.com/questions/25126471/cfrunloop-in-swift-command-line-program or https://stackoverflow.com/questions/37043857/nothing-prints-out-in-the-console-in-command-line-tool-xcode – Martin R Sep 05 '18 at 10:54
  • I'm not using Operation queues and the dispatchMain() never returns. But I want the tool to exit after the background thread is over. – imthath Sep 05 '18 at 11:50

0 Answers0