From a292ebb4cf25fe6b15f62fba1b177cc990bf2a79 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 12 Nov 2020 17:50:43 +0100 Subject: [PATCH] Support KVO for `.isFinished` and `.isCancelled` Fixes #29 --- Sources/CircularProgress/CircularProgress.swift | 8 ++++++++ readme.md | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Sources/CircularProgress/CircularProgress.swift b/Sources/CircularProgress/CircularProgress.swift index bd22b12..4f4e48f 100644 --- a/Sources/CircularProgress/CircularProgress.swift +++ b/Sources/CircularProgress/CircularProgress.swift @@ -129,6 +129,8 @@ public final class CircularProgress: NSView { private var _isFinished = false /** Returns whether the progress is finished. + + The property supports KVO. */ @IBInspectable public private(set) var isFinished: Bool { get { @@ -143,7 +145,9 @@ public final class CircularProgress: NSView { set { assertMainThread() + willChangeValue(for: \.isFinished) _isFinished = newValue + didChangeValue(for: \.isFinished) if _isFinished { isIndeterminate = false @@ -349,6 +353,8 @@ public final class CircularProgress: NSView { private var _isCancelled = false /** Returns whether the progress has been cancelled. + + The property supports KVO. */ @IBInspectable public private(set) var isCancelled: Bool { get { @@ -363,7 +369,9 @@ public final class CircularProgress: NSView { set { assertMainThread() + willChangeValue(for: \.isCancelled) _isCancelled = newValue + didChangeValue(for: \.isCancelled) if newValue { onCancelled?() diff --git a/readme.md b/readme.md index 89341a2..af35768 100644 --- a/readme.md +++ b/readme.md @@ -153,6 +153,8 @@ var onCancelled: (() -> Void)? /** Returns whether the progress is finished. + +The property supports KVO. */ @IBInspectable var isFinished: Bool { get } @@ -168,6 +170,8 @@ Displays the indeterminate state. /** Returns whether the progress has been cancelled. + +The property supports KVO. */ @IBInspectable var isCancelled: Bool { get }