繁体   English   中英

在swift3中完成5个文件下载请求后如何执行segue

[英]How to perform segue after 5 files download request completed in swift3

下载后我试图执行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,但失败。

我不确定哪一部分出错了,也许每个块都需要一个不同的名称?

请帮我。

任务不一定总是按照您将其推入队列的顺序终止。

您还必须在主线程上使用UI操作!

请参阅这篇文章如何执行一个又一个完成的多个Alamofire请求?

您也可以阅读此博客文章 ,了解使用BlockOperation的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM