psb
psb

Reputation: 141

Swift Process() and Xojo Shell

A question for someone who speaks both Swift and Xojo…

As shell objects in Xojo can be run both synchronously and asynchronously, how can a Swift Process() be run the same way?

With Xojo I can run a shell and respond accordingly when data is received from the process being run, thus not locking up the UI during long processes.

With Swift I only know how to run a Process() and handle the resulting data in one lump.

Can anyone who is familiar with Swift Process() please offer me any insights?

Upvotes: 1

Views: 118

Answers (1)

DoTryCatch
DoTryCatch

Reputation: 1082

In swift you can run the process in the dispatch queue async.

DispatchQueue.main.async {
  // your task here
}

DispatchQueue.global(qos: .userInitiated).async {
 // your task here
}

DispatchQueue.global(qos: .background).async {
 // your task here
}

In your case I would recommend searching on GitHub for swift "shell" packages.
If you don't want to use packages you will find a lot of examples when searching for DispatchQueue async.
The best to start with:
https://www.hackingwithswift.com/read/9/4/back-to-the-main-thread-dispatchqueuemain

Upvotes: 0

Related Questions