-
-
Save sturdysturge/5df5aa065afe95115dd6ec7fb218349c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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