【发布时间】:2022-10-12 22:50:27
【问题描述】:
我想在同一个屏幕上进行多个 API 调用,但是当一个 api 失败时,不应该调用其他 api?下面的代码工作正常。但我需要的是,如何以更简单的方式重构它?
ApplicationService.requestAppEndPointUrl { success, error in
if success {
ApplicationService.appLinkDownload { success, error in
if success{
ApplicationService.requestApplicationSession { success, error in
if success {
ApplicationService.validateSdk { success, error in
if success {
ApplicationService.requestApplicationDetails { success, error in
if success{
print("Success")
}
else{
self.showErrorAlert(error)
}
}
}else{
self.showErrorAlert(error)
}
}
}else{
self.showErrorAlert(error)
}
}
}else{
self.showErrorAlert(error)
}
}
}else{
self.showErrorAlert(error)
}
}
【问题讨论】: