作者:霸气的饭桶丶_130 | 来源:互联网 | 2023-01-22 17:25
我有一个使用旧的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()
}
})
Dávid Pászto..
5
语法已更改为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的自动完成功能,在寻找新的语法/方法时,可以节省大量时间。
1> Dávid Pászto..:
语法已更改为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的自动完成功能,在寻找新的语法/方法时,可以节省大量时间。