I have class with multiple function. In that class two functions I have called web service, the first web service function works proper. But second web service method not waiting for response from the service it can automatically call another service I have Used
let saveSemaphore = dispatch_semaphore_create(0) as dispatch_semaphore_tlet count = arrDeleteExecutionDetails.countfor (index, object) in arrDeleteExecutionDetails.enumerate(){ Common.checklistExecute = object let request = "\(Common.webServiceURL!)/ProInspectorJson.svc/DeleteExecutionDetails?pExecutionDetailsId=\(object.id_ExecutionDetails!)" let webservice = WebServiceCall(url: request, delegate: self) webservice.webServiceGetMethod(request) if index != count-1 { dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER) } else { dispatch_semaphore_signal(semaphore) }
The above method working properly
for checklistExecution in arrExecutionDetails{ Common.checklistExecute = checklistExecution let request = "\(Common.webServiceURL!)/ProInspectorJson.svc/SaveExecutionV3?scheduleID=\(checklistExecution.id_Agendamentor!)&userID=\(Common.userId!)&ID_PI_ChecklistConfiguration=\(checklistExecution.id_ChecklistConfig!)&Observations=\(checklistExecution.observation!)&ID_PI_tblMastRiskFactor=\(checklistExecution.id_RiskFactor!)&CorrectiveAction=\(checklistExecution.correctiveActions!)&ID_PI_FormulaResultsHeader=0&Longitude=0&Lattitude=0&checklistExecutionId=\(checklistExecution.id_ExecutionDetails!)&ErrorCode=0&ID_PI_ObjectSubCategory=\(checklistExecution.objectSubCategory!)" let webservice = WebServiceCall(url: request, delegate: self) webservice.webServiceGetMethod(request) dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)}
But the second one not working
for
loop have 5 element, the 5 elements called simultaneously. It is not waiting for first service response.
dispatch_semaphore_signal(semaphore)
I have called perfectly.