어떻게 클로저를 동기화 할 수 있습니까? ?어떻게 클로저를 동기화 할 수 있습니까?
나는이 코드를 가지고 : 내 코드에서
private func getWeather(parameters: [String : Any], failure: ((String) -> Void)? = nil ,completion: (() -> Void)? = nil) {
for _ in 0...10 {
RequestManager.sharedInstance.request(url: baseURL, parameters: parameters, completion: { (result) in
if JSON.parse(result)["name"].string == nil {
failure?("Something went wrong. Please, try again later")
} else {
let weatherModel: WeatherModel = WeatherModel(json: JSON.parse(result))
}
})
}
completion?()
}
, 완료() 모든 요청 종료됩니다하지 않을 경우, 호출을 내가 완료 전화를 필요로하는 모든 요청()을 종료 할 때. 내가 할 수 있니?
연구 'DispatchGroup'. – rmaddy
[다음은 훌륭한 튜토리얼입니다.] (https://dispatchswift.com/introduction-to-dispatch-group-a5cf9d61ff4f) –
또는 nsoperation (대기열) 및 설정 종속성에 대해 살펴보십시오 – vikingosegundo