MIO*_*OSY 4 ios swift ios8 swift3
我有一个使用旧的Swift代码开发的应用程序。现在,我将其更新为最新的Swift语法。在进行更新时,我发现调度队列中存在困难,这里给出了两个警告,因为在iOS 8中不推荐使用global(priority),在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()
}
})
Run Code Online (Sandbox Code Playgroud)
语法已更改为DispatchQueue.global(qos: DispatchQoS.QoSClass)
。您不需要调用async(execute)
,您可以直接调用async
并编写要在闭包中执行的代码。
DispatchQueue.global(qos: .background).async{ [weak self] in
if let strongSelf = self {
strongSelf.populateOutBoundContacts()
strongSelf.lookForContactsToPresent()
}
}
Run Code Online (Sandbox Code Playgroud)
在更新旧代码时,我强烈建议您仔细阅读各个类的文档并使用Xcode的自动完成功能,在寻找新的语法/方法时,可以节省大量时间。
归档时间: |
|
查看次数: |
725 次 |
最近记录: |