title: How do you return from an asynchronous NSURLConnection to the calling class?
body: <p>I've got the following class which makes an HTTP post request asynchronously to avoid problems on the main UI thread:</p>
  
  <pre><code>@implementation DataFeeder
  
  -(void) doLookup:(NSString *)inputValue
  {
      NSString *myRequestString = [NSString stringWithFormat:@"val=%@", inputValue];
      NSMutableData *myRequestData = [ NSMutableData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
  
      NSURL * myUrl = [NSURL URLWithString: @"http://mywebsite/results.php"];
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: myUrl]; 
      [request setHTTPMethod: @"POST"];
      [request setHTTPBody: myRequestData];
      [request setTimeoutInterval:10.0];
  
      [[NSURLConnection alloc] initWithRequest:request delegate:self];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
      responseData = [[NSMutableData alloc] init];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
      [responseData appendData:data];
  }
  
  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
      // Show error message
  }
  
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
      // Use responseData
      // Got all my response data here, so build up an object ready to send back
  }
  
  @end
  </code></pre>
  
  <p>I'm invoking the above from my <code>ViewController</code> using the following line of code :</p>
  
  <p><code>MyObject * myObj = [feeder doLookup:@"SomeStaticStringForNow"];</code></p>
  
  <p>So, this is how I understand it :</p>
  
  <ol>
  <li>The <code>doLookup</code> will execute the request on an asynchronous
  connection.</li>
  <li>When the data has been fully loaded, it will invoke <code>connectionDidFinishLoading</code></li>
  <li>Once the data has finished loading, I will build up an object from the response data that I will send back to the calling controller</li>
  </ol>
  
  <p>How can I have the calling controller listen out for this? Do I need to implement my own callback methods in the ViewController that will listen out for invocation and then stop a spinner and update the UI based on the contents of <code>myObj</code> ?</p>
  
  <p>I'm hoping theres a really easy way that I've overlooked...</p>
  
  <p>Thanks</p>