title: NSURLConnection NSURLRequest proxy for asynchronous web service calls
body: <p>I have multiple views which make the same <code>NSURLRequest/NSURLConnection request</code>. Ideally, in order to get some code reuse, I'd like to have some sort of a "proxy" which does all the underlying work of creating/executing the (asynchronous) request/connection, setting up all the delegate methods, etc., so I don't have to copy all those <code>NSURLConnection</code> delegate method handlers in each view. First of all, is this design approach reasonable? Second, how would I go about doing something like that?</p>
  
  <p>For a little background info, I attempted this and got it to "work", however, it doesn't appear to be executing asynchronously. I created a Proxy.h/m file which has instance methods for the different web service calls (and also contains the <code>NSURLConnection</code> delegate methods):</p>
  
  <pre><code>@interface Proxy : NSObject {
  
      NSMutableData *responseData;
      id&lt;WSResponseProtocol&gt; delegate;
  }
  
  - (void)searchForSomethingAsync:(NSString *)searchString delegate:(id&lt;WSResponseProtocol&gt;)delegateObj;
  
  @property (nonatomic, retain) NSMutableData *responseData;
  @property (assign) id&lt;WSResponseProtocol&gt; delegate;
  
  @end
  </code></pre>
  
  <p>The WSResponseProtocol is defined as such:</p>
  
  <pre><code>@protocol WSResponseProtocol &lt;NSObject&gt;
  
  @optional
  - (void)responseData:(NSData *)data;
  - (void)didFailWithError:(NSError *)error;
  
  @end
  </code></pre>
  
  <p>To use this, the view controller simply needs to conform to the <code>WSResponseProtocol</code> protocol, to catch the response(s). Making the web service call is done like so:</p>
  
  <pre><code>Proxy *p = [[Proxy alloc] init];
  [p searchForSomethingAsync:searchText delegate:self];
  [p release];
  </code></pre>
  
  <p>I can provide more code but the remaining can be assumed. Before calling, I "startAnimating" a <code>UIActivityIndicatorView</code> spinner. But the spinner never spins. If I simply put the NSURLConnection delegate methods directly in the view controller, then the spinner spins. So, it makes me think that my implementation isn't executing asynchronously. Any thoughts/ideas here?</p>