title: How do I start an Asynchronous NSURLConnection inside an NSOperation?
body: <p>I want to do an Asynchrous NSURLConnection inside of an NSOperation on a background thread.
  it is because I'm doing some very expensive operations on the data as they come back.</p>
  
  <p>This is a very similar question to what they asked here:
  <a href="https://stackoverflow.com/questions/1304508/how-do-i-do-an-asychronous-nsurlconnection-inside-an-nsoperation">How do I do an Asynchronous NSURLConnection inside an NSOperation?</a></p>
  
  <p>but the difference is that I run the connection in another class.</p>
  
  <p>Here is my first attempt:</p>
  
  <p>In my MainViewController:</p>
  
  <pre><code>@property (nonatomic, strong) NSOperationQueue *requestQueue;
  
  #pragma mark - Lazy initialization
  - (NSOperationQueue *)requestQueue 
  {
      if (!_requestQueue) {
          _requestQueue = [[NSOperationQueue alloc] init];
          _requestQueue.name = @"Request Start Application Queue";
          _requestQueue.maxConcurrentOperationCount = 1;
      }
      return _requestQueue;
  }
  
  -(void)callToServer
  {
  URLJsonRequest *request = [URLRequestFactory createRequest:REQUEST_INTERFACE_CLIENT_VERSION
                                                           delegate:self];
  
      RequestSender *requestSender = [[RequestSender alloc]initWithPhotoRecord:request delegate:self];
  
     [self.requestQueue addOperation:requestSender];
  }
  </code></pre>
  
  <p>Here is my operation:</p>
  
  <pre><code>- (id)initWithPhotoRecord:(URLJsonRequest *)request
                   delegate:(id&lt;RequestSenderDelegate&gt;) theDelegate{
  
      if (self = [super init])
      {
          self.delegate = theDelegate;
          self.jsonRequest = request;
      }
      return self;
  }
  
  - (void)main {
  
      //Apple recommends using @autoreleasepool block instead of alloc and init NSAutoreleasePool, because blocks are more efficient. You might use NSAuoreleasePool instead and that would be fine.
      @autoreleasepool
      {
  
          if (self.isCancelled)
              return;
  
          [self.jsonRequest start];
  
      }
  }
  </code></pre>
  
  <p>Here is my Request  start function:</p>
  
  <pre><code>-(void) start
  {
    NSURL *url = [NSURL URLWithString:@"http://google.com"];
   NSURLRequest *theRequest = [NSURLRequest requestWithURL:url];
    urlConnection = [[[NSURLConnection alloc]    initWithRequest:theRequest delegate:self]autorelease];
  
  [urlConnection start];
  [theRequest release]
  }
  
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
      NSLog(@"Received reponse from connection");
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
  
  
  
  }
  
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection{
  
  }
  
  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
  
  }
  </code></pre>
  
  <p>I do not get a response from the server.</p>