Most of my programming experience is in Shell and Python. I'm fairly new to Swift, like "3 days ago" new. I just can't figure out why didFinishDownloadtingTo is not called when my downloadTask completes. Here's my AppDelegate.swift file:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, URLSessionDelegate, URLSessionDownloadDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet var progressind: NSProgressIndicator!
@IBOutlet var outputtext: NSTextField!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
let requestURL: URL = URL(string: "https://www.apple.com")!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared
let downloads = session.downloadTask(with: urlRequest)
print("starting download...")
downloads.resume()
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL){
print("download finished!")
}
}
I'm using Swift 3, and I just cannot find enough documentation on it to figure this out on my own.
I went a little crazy declaring classes trying to figure out why it wasn't working right, so I'm sure there are also some errors there.
It appears to download the file successfully. I've tried with several URLs. The "Disk" and "Network" sections of the debug menu appear consistent with downloading a file of the size at every URL I've tested with.