infinitedev108
infinitedev108

Reputation: 21

How to increment NSProgressIndicator and update the view while inside a function?

This is a very simple situation but I cannot seem to find the answer anywhere.

I'm building a Mac app in swift. So far I have a blank storyboard with one NSButton and one determinate NSProgressIndicator

The progress indicator was control+dragged into the Swift file for the ViewController to create an outlet called ProgressBar

The button was control+dragged into the Swift file for the ViewController so that it calls the function ButtonFunction(sender: NSButton) every time the button is clicked.

Inside ButtonFunction, I execute some code, call some other functions, and do a bunch of different unrelated actions. And after each action inside ButtonFunction, I have ProgressBar.increment(by:20)

The goal is basically just to increment ProgressBar a little bit more every time ButtonFunction executes the next line of code.

But the problem is, the progress indicator on the storyboard stays blank and only shows full blue / 100% at the very end when ButtonFunction has gone through all its lines of code and returned.

All of the ProgressBar.increment(by:20) statements appear to do absolutely nothing until the very end.

How can I repeatedly update the view of my application to show the advancing progress bar while executing the code inside of ButtonFunction?

I already tried calling loadView() inside ButtonFunction but it has no effect on the state of the progress indicator until the function is done or returns a value. I would like to update the view over and over again while inside of functions.

Upvotes: 1

Views: 434

Answers (0)

Related Questions