gpt4 book ai didi

ios - 优先级和背景在 iOS 8 中被弃用

转载 作者:可可西里 更新时间:2023-11-01 00:56:41 24 4
gpt4 key购买 nike

我有一个应用程序是用旧的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com