Skip to content

Commit

Permalink
Support KVO for .isFinished and .isCancelled
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
sindresorhus committed Nov 12, 2020
1 parent 322833a commit a292ebb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/CircularProgress/CircularProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -143,7 +145,9 @@ public final class CircularProgress: NSView {
set {
assertMainThread()

willChangeValue(for: \.isFinished)
_isFinished = newValue
didChangeValue(for: \.isFinished)

if _isFinished {
isIndeterminate = false
Expand Down Expand Up @@ -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 {
Expand All @@ -363,7 +369,9 @@ public final class CircularProgress: NSView {
set {
assertMainThread()

willChangeValue(for: \.isCancelled)
_isCancelled = newValue
didChangeValue(for: \.isCancelled)

if newValue {
onCancelled?()
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ var onCancelled: (() -> Void)?

/**
Returns whether the progress is finished.
The property supports KVO.
*/
@IBInspectable var isFinished: Bool { get }

Expand All @@ -168,6 +170,8 @@ Displays the indeterminate state.

/**
Returns whether the progress has been cancelled.
The property supports KVO.
*/
@IBInspectable var isCancelled: Bool { get }

Expand Down

0 comments on commit a292ebb

Please sign in to comment.