Note that there are some explanatory texts on larger screens.

plurals
  1. PODownloading multiple files writes same data to all files
    text
    copied!<p>Attempting to download multiple files from an XML feed. There are several Categories and each category has an unknown amount of images. I create a subdirectory for each category, no problem. When I try to download each file to the respective category, every file is written with the same data for every image there is in the feed.</p> <h2>I guess my question is how can I download 1 file at a time to the corresponding directory without overwriting all of the images with the same data?</h2> <pre><code>-(void)parsingComplete:(XMLDataSource*)theParser { /* iterate through the Categories and create the sub-directory if it does not exist */ for (int i = 0; i &lt; [categories count]; i++) { NSString *cat = [NSString stringWithFormat:@"%@/%@",BASE_DIR,[[categories objectAtIndex:i] objectForKey:@"name"]]; NSString *catName = [[categories objectAtIndex:i] objectForKey:@"name"]; NSArray *catArray = [[categories objectAtIndex:i] objectForKey:@"images"]; /* create the sub-direcotry naming it the #category# key */ if (![FILEMANAGER fileExistsAtPath:cat]) { [FILEMANAGER createDirectoryAtPath:cat withIntermediateDirectories:NO attributes:nil error:nil]; } //NSLog(@"\n\nCategory: %@",cat); for (int x = 0; x &lt; [catArray count]; x++) { /* download each file to the corresponding category sub-directory */ fileOut = [NSString stringWithFormat:@"%@/%@_0%i.jpg",cat,catName,x]; NSURLRequest * imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[[catArray objectAtIndex:x] objectForKey:@"imageUrl"]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0]; [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self]; } } } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [receivedData writeToFile:fileOut atomically:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload