How to correctly add a spinner on macOS Catalina as Style.spinning is deprecated?

818 Views Asked by At

I always create a spinner with NSProgressIndicator like this

let spinner = NSProgressIndicator()
spinner.style = .spinning

It works fine, but I recently found the NSProgressIndicator.Style.spinning is deprecated. I have went searched around, but did not quite find out what is the recommended way right now to create a spinner on macOS. Can anyone please help here?

Thank you

2

There are 2 best solutions below

1
Willeke On BEST ANSWER

It looks like an error in the documentation. In macOS 10.15 NSProgressIndicatorBarStyle and NSProgressIndicatorSpinningStyle are deprecated. Somehow NSProgressIndicatorStyleBar and NSProgressIndicatorStyleSpinning, .bar and .spinning in Swift, were also deprecated in the documentation but they aren't in NSProgressIndicator.h.

typedef NS_ENUM(NSUInteger, NSProgressIndicatorStyle) {
    NSProgressIndicatorStyleBar = 0,
    NSProgressIndicatorStyleSpinning = 1
};

and

/* Please instead use the more modern versions of these constants.
 */
static const NSProgressIndicatorStyle NSProgressIndicatorBarStyle API_DEPRECATED_WITH_REPLACEMENT("NSProgressIndicatorStyleBar", macos(10.2,10.14)) = NSProgressIndicatorStyleBar;
static const NSProgressIndicatorStyle NSProgressIndicatorSpinningStyle API_DEPRECATED_WITH_REPLACEMENT("NSProgressIndicatorStyleSpinning", macos(10.2,10.14)) = NSProgressIndicatorStyleSpinning;
0
Lee Ann Rucker On

The style isn't deprecated; they've just been making the names consistent so it's easier to turn them into Swift.