Skip to content

Instantly share code, notes, and snippets.

@chriswebb09
Last active May 11, 2017 09:50
Show Gist options
  • Save chriswebb09/e1d28af648bd47c7c8384f512efa238e to your computer and use it in GitHub Desktop.
Save chriswebb09/e1d28af648bd47c7c8384f512efa238e to your computer and use it in GitHub Desktop.
final class Download {
weak var delegate: DownloadDelegate?
var url: String?
var downloadTask: URLSessionDownloadTask?
var progress: Float = 0.0 {
didSet {
updateProgress()
if progress == 1 {
downloadTask = nil
print("File is done")
}
}
}
// Gives float for download progress - for delegate
private func updateProgress() {
if let task = downloadTask,
let url = url {
delegate?.downloadProgressUpdated(for: progress)
}
}
init(url: String) {
self.url = url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment