作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个应用程序是用旧的 swift 代码开发的。现在我正在将它更新为最新的快速语法。在更新时我发现调度队列很困难,这里给出了两个警告,因为 global(priority) 在 ios 8 中被弃用,而 background 在 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()
}
})
最佳答案
语法更改为 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 的自动完成功能,它可以为您节省大量寻找新语法/方法的时间。
关于ios - 优先级和背景在 iOS 8 中被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45735707/
我是一名优秀的程序员,十分优秀!