代码:
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
let download = self.downloads[downloadTask.taskIdentifier]!
var fileError: NSError?
var resultingURL: NSURL?
if NSFileManager.defaultManager().replaceItemAtURL(download.destinationURL, withItemAtURL: location, backupItemName: nil, options: nil, resultingItemURL: &resultingURL, error: &fileError) {
download.resultingURL = resultingURL
} else {
download.error = fileError
}
}
出错:
/Users/crifan/dev/dev_root/daryun/JianDao/iOS-Client/JianDao/TCBlobDownloadManager.swift:180:185: Extra argument ‘error’ in call
extra argument ‘error’ in call swift
ios – Swift 2 Extra argument ‘ error’ in call – Stack Overflow
改为:
// if NSFileManager.defaultManager().replaceItemAtURL(download.destinationURL, withItemAtURL: location, backupItemName: nil, options: nil, resultingItemURL: &resultingURL, error: &fileError) {
// download.resultingURL = resultingURL
// } else {
// download.error = fileError
// }
do {
try NSFileManager.defaultManager().replaceItemAtURL(download.destinationURL, withItemAtURL: location, backupItemName: nil, options: nil, resultingItemURL: &resultingURL)
download.resultingURL = resultingURL
} catch let error as NSError {
download.error = error
}
结果又出错:
[已解决]swift出错:Nil is not compatible with expected argument type NSFileManagerItemReplacementOptions