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))) } }