dispatch_group_notify 已替换为实例方法 DispatchGroup.notify(qos:flags:queue:execute:)
dispatch_group_notify has been replaced by instance method DispatchGroup.notify(qos:flags:queue:execute:)
我正在尝试将我的 swift2.2
代码库迁移到 swift3
。之前,对于 GCD
,此代码曾经为我工作。但它显示 dispatch_group_notify has been replaced by instance method DispatchGroup.notify(qos:flags:queue:execute:)
的错误
我该如何解决这个错误?
dispatch_group_notify(group, dispatch_get_main_queue()) {
if productsError != nil || citiesError != nil || usersError != nil {
completionHandler(false)
} else {
completionHandler(true)
}
}
这是我正在编写的新代码,我在离开小组时卡住了。
class APIHandler {
func requestDataFromTheServerWithCompletionhandler(completionHandler: ((Bool) -> Void)) {
let group = DispatchGroup()
var productsError: NSError?
var citiesError: NSError?
var usersError: NSError?
var categoriesError: NSError?
let manager = SessionManager()
// MARK:- Products
group.enter()
let productsParser = ProductsParser()
let productsURL = URLs.productsURL
manager.requestDataWithCompetionHandler(urlString: productsURL) {( responseData, error) in
if responseData != nil {
print("Products Success")
productsParser.parseAndStoreProductsData(dataToParse: responseData!)
}
else {
print("Products Error")
productsError = error
}
group.leave()
}
dispatch_group_notify(group, DispatchQueue.main) {
if productsError != nil || citiesError != nil || usersError != nil {
completionHandler(false)
} else {
completionHandler(true)
}
}
}
}
我认为您已经将新旧两种方式结合起来...
dispatch_group_notify
是旧代码。
尝试如下:
DispatchGroup().notify(queue: DispatchQueue.main) {
}
通过变量你也可以使用 like as :
let dispatchGroup = DispatchGroup()
dispatchGroup.notify(queue: DispatchQueue.main) {
}
而且编译器显示你可以使用如下:
dispatchGroup.notify(qos: DispatchQoS.background, flags: DispatchWorkItemFlags.assignCurrentContext, queue: DispatchQueue.main) {
}
希望对你有帮助。
我正在尝试将我的 swift2.2
代码库迁移到 swift3
。之前,对于 GCD
,此代码曾经为我工作。但它显示 dispatch_group_notify has been replaced by instance method DispatchGroup.notify(qos:flags:queue:execute:)
的错误
我该如何解决这个错误?
dispatch_group_notify(group, dispatch_get_main_queue()) {
if productsError != nil || citiesError != nil || usersError != nil {
completionHandler(false)
} else {
completionHandler(true)
}
}
这是我正在编写的新代码,我在离开小组时卡住了。
class APIHandler {
func requestDataFromTheServerWithCompletionhandler(completionHandler: ((Bool) -> Void)) {
let group = DispatchGroup()
var productsError: NSError?
var citiesError: NSError?
var usersError: NSError?
var categoriesError: NSError?
let manager = SessionManager()
// MARK:- Products
group.enter()
let productsParser = ProductsParser()
let productsURL = URLs.productsURL
manager.requestDataWithCompetionHandler(urlString: productsURL) {( responseData, error) in
if responseData != nil {
print("Products Success")
productsParser.parseAndStoreProductsData(dataToParse: responseData!)
}
else {
print("Products Error")
productsError = error
}
group.leave()
}
dispatch_group_notify(group, DispatchQueue.main) {
if productsError != nil || citiesError != nil || usersError != nil {
completionHandler(false)
} else {
completionHandler(true)
}
}
}
}
我认为您已经将新旧两种方式结合起来...
dispatch_group_notify
是旧代码。
尝试如下:
DispatchGroup().notify(queue: DispatchQueue.main) {
}
通过变量你也可以使用 like as :
let dispatchGroup = DispatchGroup()
dispatchGroup.notify(queue: DispatchQueue.main) {
}
而且编译器显示你可以使用如下:
dispatchGroup.notify(qos: DispatchQoS.background, flags: DispatchWorkItemFlags.assignCurrentContext, queue: DispatchQueue.main) {
}
希望对你有帮助。