You need to execute porcessData in another thread
// Where you call ProcessData():
DispatchQueue.global(qos: .userInitiated).async {
self.ProcessData()
}
Now, as we call UI functions in processData, they must be called from main thread
func processData() {
DispatchQueue.main.async { // as we call UI function
self.statusText.stringValue = "Message 1"
}
read_data1()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 2"
}
read_data2()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 3"
}
read_data3()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 4"
}
read_data4()
DispatchQueue.main.async {
self.statusText.stringValue = "Done"
}
}
Note:
- names of func should start with lowercase
- convention is to use camelCase more than underscore: read_data1 -> readData1
- don't forget to prefix with self in Dispatch blocks
- I assumed the name of IBOutlet is statusText, not statusMessageLabel
@IBOutlet weak var statusMessageLabel: NSTextField!
You could also Dispatch in the func itself
If so, just call processData() in code directly, without enclosing in a Dispatch.
change func as:
func ProcessData() {
DispatchQueue.global(qos: .userInitiated).async {
DispatchQueue.main.async { // as we call UI function
self.statusText.stringValue = "Message 1"
}
self.read_data1()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 2"
}
self.read_data2()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 3"
}
self.read_data3()
DispatchQueue.main.async {
self.statusText.stringValue = "Message 4"
}
self.read_data4()
DispatchQueue.main.async {
self.statusText.stringValue = "Done"
}
}
}
I tested, with a dummy read, it works OK.
If it works for you, don't forget to close the thread.