Send DownloadProgressDidChange notification only when numberOfTasks or numberRemaining actually change.
This commit is contained in:
parent
1bffbb7312
commit
f7c5919674
@ -10,25 +10,29 @@ import Foundation
|
|||||||
|
|
||||||
public extension Notification.Name {
|
public extension Notification.Name {
|
||||||
|
|
||||||
public static let DownloadProgressDidChange = Notification.Name(rawValue: "DownloadProgressDidChangeNotification")
|
public static let DownloadProgressDidChange = Notification.Name(rawValue: "DownloadProgressDidChange")
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DownloadProgress {
|
public final class DownloadProgress {
|
||||||
|
|
||||||
public var numberOfTasks = 0 {
|
public var numberOfTasks = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
if numberOfTasks == 0 {
|
if numberOfTasks == 0 {
|
||||||
numberRemaining = 0
|
numberRemaining = 0
|
||||||
}
|
}
|
||||||
|
if numberOfTasks != oldValue {
|
||||||
postDidChangeNotification()
|
postDidChangeNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var numberRemaining = 0 {
|
public var numberRemaining = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
|
if numberRemaining != oldValue {
|
||||||
postDidChangeNotification()
|
postDidChangeNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var numberCompleted: Int {
|
public var numberCompleted: Int {
|
||||||
get {
|
get {
|
||||||
@ -65,6 +69,8 @@ public class DownloadProgress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Private
|
||||||
|
|
||||||
private extension DownloadProgress {
|
private extension DownloadProgress {
|
||||||
|
|
||||||
func postDidChangeNotification() {
|
func postDidChangeNotification() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user