【问题标题】:priority and background was deprecated in ios 8优先级和背景在 ios 8 中已弃用
【发布时间】:2017-08-17 12:54:47
【问题描述】:

我有一个使用旧的 swift 代码开发的应用程序。现在我将它更新为最新的 swift 语法。在更新时我发现调度队列很困难,这里它给出了两个警告,因为全局(优先级)在 ios 8 中已弃用,而背景在 ios 8 中已弃用。

DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.background).async(execute: { [weak self] in     //Getting warning in this line
    if let strongSelf = self {
        strongSelf.populateOutBoundContacts()
        strongSelf.lookForContactsToPresent()
    }
})

【问题讨论】:

标签: ios swift swift3 ios8


【解决方案1】:

语法已更改为DispatchQueue.global(qos: DispatchQoS.QoSClass)。不需要调用async(execute),可以直接调用async,在闭包中编写要执行的代码。

DispatchQueue.global(qos: .background).async{ [weak self] in    
    if let strongSelf = self {
        strongSelf.populateOutBoundContacts()
        strongSelf.lookForContactsToPresent()
    }        
}

在更新旧代码时,我强烈建议您阅读各个类的文档并使用 Xcode 的自动完成功能,它可以为您节省大量寻找新语法/方法的时间。

【讨论】:

  • 很高兴我能帮上忙。如果您觉得我的回答有用,请考虑接受。
猜你喜欢
  • 2011-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多