【问题标题】:Swift 3: Can not convert value of type 'int' to expected argument type 'DispatchQueue.GlobalQueuePriority'Swift 3:无法将“int”类型的值转换为预期的参数类型“DispatchQueue.GlobalQueuePriority”
【发布时间】:2016-09-22 12:12:58
【问题描述】:

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

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

})

【问题讨论】:

    标签: ios iphone swift swift2 swift3


    【解决方案1】:

    警告,iOS 8 已弃用此功能,请参阅下文了解最新信息

    DispatchQueue.global 需要 DispatchQueue.GlobalQueuePriority 枚举,即:

    • 默认
    • 背景

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

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

    如果你想要最低优先级。

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

    最新解决方案:

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

    这为您提供了更多选择:

    • 背景
    • 实用程序
    • 默认
    • 用户发起
    • 用户交互
    • 未指定

    【讨论】:

    • 我想知道新选项中不推荐使用的“高”是什么意思!
    • @ioopl 可能是userInteractive,因为那是最高的。
    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2019-05-12
    • 2016-08-01
    • 1970-01-01
    • 2017-01-30
    • 2017-02-13
    • 2017-02-07
    • 1970-01-01
    相关资源
    最近更新 更多