Last active
May 11, 2017 09:50
-
-
Save chriswebb09/e1d28af648bd47c7c8384f512efa238e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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