title: App not downloading files using NSURLConnection
body: <p>I have an app that loops through an array of URLs and downloads all the files in that array (10 small txt files and 1 large image file).  I had the app downloading the files ok before but due to a problem with the large image, I had to subclass NSURLConnection and I think I haven't quite got it right as no files are now being downloaded.</p>
  
  <p>For each item of the array getFiles is passed a URL and run:</p>
  
  <pre><code>-(void)getFile:(NSString*)url tag:(NSString*)tag {
      NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
      FileURLConnection *connection = [[FileURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES tag:tag];
      if (connection) {
          [receivedData setObject:[NSMutableData data] forKey:connection.tag];
      }
  }
  </code></pre>
  
  <p>Here are the NSURLConnection delegates:</p>
  
  <pre><code>-(NSMutableData*)dataForConnection:(FileURLConnection*)connection {
      NSMutableData *data = [receivedData objectForKey:connection.tag];
      return data;
  }
  - (void)connection:(FileURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
      NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:fileName];
      NSMutableData *dataForConnection = [self dataForConnection:(FileURLConnection*)connection];
      [dataForConnection setLength:0];
  }
  - (void)connection:(FileURLConnection *)connection didReceiveData:(NSData *)data {
      NSMutableData *dataForConnection = [self dataForConnection:(FileURLConnection*)connection];
      [dataForConnection appendData:data];
  }
  - (NSCachedURLResponse *)connection:(FileURLConnection *)connection
                willCacheResponse:(NSCachedURLResponse*)cachedResponse {
      return nil;
  }
  - (void)connectionDidFinishLoading:(FileURLConnection *)connection {
      NSLog(@"connectionDidFinishLoading run");
      NSMutableData *dataForConnection = [self dataForConnection:(FileURLConnection *)connection];
      NSString *fileName = connection.tag;
      NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:fileName];
      [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
      file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
      [file seekToEndOfFile];
      [file writeData:dataForConnection];
      [file closeFile];
  }
  </code></pre>
  
  <p><strong>EDIT</strong>: If I NSLog the receivedData (NSDictionary) in getFile it updates the 'tag' object but no data to go with it:</p>
  
  <pre><code>"accomodation.txt" = &lt;&gt;;
  "future-congress-dates.txt" = &lt;&gt;;
  "general-file.txt" = &lt;&gt;;
  ...
  </code></pre>
  
  <p>I have also tried to NSLog the dataForConnection (NSMutableData) for each delegate but nothing ever gets printed:</p>
  
  <pre><code>NSLog(@"dataForConnection %@", dataForConnection);
  </code></pre>