简体   繁体   English

如何使用audioFileUrls实现OperationQueue-Swift-Xcode 11 beta 5

[英]How to implement OperationQueue with audioFileUrls - Swift - Xcode 11 beta 5

I am trying to implement NSOperationQueue in order to be able to cancel a process which merges audio files (using (audioFileUrls: NSArray) method) but I don't know how to implement it, I am getting confused by the different exemples accessibles. 我正在尝试实现NSOperationQueue,以便能够取消合并音频文件的过程(使用(audioFileUrls:NSArray)方法),但是我不知道如何实现它,不同的示例可访问性使我感到困惑。 Could someone add the missing code in the exemple I am providing here? 有人可以在我在此处提供的示例中添加缺少的代码吗? Thanks. 谢谢。

Import Cocoa
Import AVFoundation

let queue = OperationQueue.main

@IBAction func build(_ sender: NSButton){
   builder()
}

@IBAction func cancel(_ sender: NSButton){
   queue.cancelAllOperations()
}

func builder() {
   queue.maxConcurrentOperationCount = 1                   
   queue.addOperation {...}
}

You should create your own queue 您应该创建自己的队列

lazy var myOperationQueue: OperationQueue = {
    var queue = OperationQueue()
    queue.name = "Image merge queue"
    queue.maxConcurrentOperationCount = 1
    return queue
  }()

and then use it in the builder() 然后在builder()使用它

func builder() {
   myOperationQueue.addOperation {...}
}

Also keep in mind that cancel does not cancel operation that are currently in execution documentation 还请记住,取消不会取消执行文档中当前的操作

Canceling the operations does not automatically remove them from the queue or stop those that are currently executing. 取消操作不会自动将其从队列中删除或停止当前正在执行的操作。

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

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