【问题标题】:How to perform segue after 5 files download request completed in swift3如何在swift3中完成5个文件下载请求后执行segue
【发布时间】:2017-08-12 14:46:28
【问题描述】:

我正在尝试下载后执行 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 附加到此数组中,但失败了。

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

请帮帮我。

【问题讨论】:

    标签: ios swift segue grand-central-dispatch


    【解决方案1】:

    任务并不总是按照您将它们推入队列的顺序终止。

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

    看到这个帖子How is it possible to perform multiple Alamofire requests that are finished one after another?

    您也可以阅读this blog post 了解使用BlockOperation 的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 2013-10-17
      相关资源
      最近更新 更多