Caps-iOS/Caps/Download/ClassifierProgressObserver.swift

21 lines
671 B
Swift
Raw Permalink Normal View History

import Foundation
final class ClassifierProgressObserver: NSObject {
weak var delegate: ClassifierProgressDelegate?
}
extension ClassifierProgressObserver: URLSessionDownloadDelegate {
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
}
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
delegate?.classifierProgress(.init(
bytesLoaded: Double(totalBytesWritten),
total: Double(totalBytesExpectedToWrite)))
}
}