I am trying to perform segue after downloading. I tried BlockOperation firstly, but I failed.
Below is my code.
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) }
I want to set a array of [BlockOperation] firstly.
Then, trying to append Alamofire.download in this array, but failed.
I am not sure which part got wrong, maybe each block need a different name?
Please help me.