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

标签 ios swift swift3 ios8

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

相关文章:

iphone - iOS 6 中的镶边/回声/混响效果

iOS plist 为空

ios - 尝试使用按钮更改 WebView 网址,但当我按下它时,应用程序崩溃了

ios - 在 Web App 和 IOS App 之间持久化用户

ios - 在回调函数上设置 uilabel

ios - 在 Swift 中将 AnyObject 添加到 NSMutableArray

ios - 为旋转的 UIView 找到给定 y 的最小 x

swift - 跳跃列表实现的随机数生成器

ios - TableView :didSelectRowAtIndexPath fails

ios - AVPlayer removeTimeObserver 使应用程序崩溃(swift 3)