Swift 3:无法将'int'类型的值转换为预期的参数类型'DispatchQueue.GlobalQueuePriority'

Kir*_*nee 24 iphone ios swift swift2 swift3

Swift 3.0:Can not convert value of type 'int' to expected argument type 'DispatchQueue.GlobalQueuePriority'创建调度异步队列时 收到错误

DispatchQueue.global(priority: 0).async(execute: { () -> Void in

})
Run Code Online (Sandbox Code Playgroud)

Dej*_*dar 42

警告,这在iOS 8中已弃用,请参阅下面的最新信息

DispatchQueue.global期待DispatchQueue.GlobalQueuePriority枚举,即:

  • 默认
  • 背景

所以在你的情况下,你只需写:

DispatchQueue.global(priority: .background).async(execute: { () -> Void in

})
Run Code Online (Sandbox Code Playgroud)

如果您想要最低优先级.

快速检查显示,DispatchQueue.global(priority:_)在iOS 8中已弃用.

最新方案:

DispatchQueue.global(qos: .background).async {

}
Run Code Online (Sandbox Code Playgroud)

这为您提供了更多选择:

  • 背景
  • 效用
  • 默认
  • 用户引发
  • userInteractive
  • 不明

  • @ioopl可能是'userInteractive`,因为那是最高的. (3认同)