我正在尝试下载后执行segue。 我先尝试了BlockOperation,但失败了。
下面是我的代码。
let operationQ = OperationQueue()
let taskArray: [BlockOperation]
for index in 0..<songsList.count {
let eachSong = songsList[index]
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = NSHomeDirectory() + "/Documents/"
let fileURL = URL(fileURLWithPath: documentsURL.appending("song\(index).m4a"))
print("song\(index).m4a is downloading")
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
taskArray.append(BlockOperation(block: let task = {
Alamofire.download(eachSong, to: destination).response { _ in
// print(response.response)
}
}))
taskArray[4].completionBlock = { performSegue(withIdentifier: "NextVC", sender: self) }
我想先设置一个[BlockOperation]数组。
然后,尝试将 Alamofire.download 追加到该数组中,但失败了。
我不确定哪一部分出了问题,也许每个 block 都需要不同的名称?
请帮助我。
最佳答案
任务并不总是按照您将它们插入队列的顺序终止。
您还必须在主线程上使用 UI 操作!
查看这篇文章How is it possible to perform multiple Alamofire requests that are finished one after another?
您还可以阅读this blog post有关使用 BlockOperation
关于ios - 如何在swift3中完成5个文件下载请求后执行segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651518/