title: Wait on main thread until an asynchronous process is completed?
body: <p>I am using a proxy which is making asynchronous network calls. The response is to be processed and passed as an argument to the method in the next line. The code illustration is below:</p>
  
  <pre><code>- (MyClass *) performOperations{
    ...
    ...
    [self callProxyMethodsTarget:self action:@selector(receivedValue:) withObject:anObject]; //making an asynchronous call here
    return response;
  }
  
  - (void) receivedValue:(id)response{     ///need this return value from network call to return from performOperartions
    ...
    ...
  }
  </code></pre>
  
  <p>My problem is that as the proxy methods are making asynchronous network calls, I am not able to get the response in time to return it.</p>
  
  <p>I have thought of many things, like:</p>
  
  <ul>
  <li>making the network calls synchronous but that would require a lot of rework and may introduce unforeseen issues</li>
  <li>changing the return type and pass the response from receivedValue, but can't do that as my client has defined these method names and return types and on other platforms the team is using synchronous calls</li>
  </ul>
  
  <p>I have thought of a solution like:</p>
  
  <pre><code> - (MyClass *) performOperations{
        ...
        ...
        [self callProxyMethodsTarget:self action:@selector(receivedValue:) withObject:anObject]; //making an asynchronous call here
  
        ///write a code here to wait until response is received
        return response;
      }
  
      - (void) receivedValue:(id)response{     ///need this return value from network call to return from performOperartions
        ...
        ...
      }
  </code></pre>
  
  <p>But have failed to do so.</p>