Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 3, 2021 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/5df5aa065afe95115dd6ec7fb218349c to your computer and use it in GitHub Desktop.
Save sturdysturge/5df5aa065afe95115dd6ec7fb218349c to your computer and use it in GitHub Desktop.
import Foundation
protocol DownloadDelegate: class {
func downloadProgressUpdated(for progress: Float)
}
final class Download {
weak var delegate: DownloadDelegate?
var url: URL
var downloadTask: URLSessionDownloadTask?
var progress: Float = 0.0 {
didSet {
updateProgress()
if progress == 1 {
downloadTask = nil
}
}
}
private func updateProgress() {
if downloadTask != nil {
delegate?.downloadProgressUpdated(for: progress)
}
}
init(url: URL) {
self.url = url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment