title: MKNetworkKit download multiple files and wait for all to be ready using addDependency
body: <p>I want my application to download a zipfile and a couple of movies. I want to wait for all of them to be ready before continuing my app.
  Here's the code so far. The problem is, the application will always continue as soon as the zipfile is downloaded and unzipped, it will not wait for the movies to complete. I have set all the movie operations as dependency in the 'main' operation, but that did not help.
  What am I missing?</p>
  
  <pre><code>// create our network engine
  MKNetworkEngine* engine = [[MKNetworkEngine alloc]
                             initWithHostName:hostName customHeaderFields:nil];
  
  // Main operation for our app download.
  MKNetworkOperation *op = [engine operationWithPath:appUpdateFile];
  
  // If we have videos, create operations for them
  // We add them to an array, so we can start them later
  
  NSMutableArray *videoOperations = [[NSMutableArray alloc] init];
  if ([appVideos isEqual:@"no_videos"]) {
      NSLog(@"We have no videos");
  } else {
      for(id anObject in appVideos) {
          MKNetworkOperation *opVideo = [engine operationWithPath:[anObject valueForKey:@"downloadUrl"]];
          // add this operation as a dependency to our main operation
          [op addDependency:opVideo];
          NSString *videoFilePath = [videoFolder stringByAppendingPathComponent:[anObject valueForKey:@"name"]];
          [opVideo addDownloadStream:[NSOutputStream outputStreamToFileAtPath:videoFilePath append:YES]];
          [opVideo addCompletionHandler:^(MKNetworkOperation *completedOperation) {
              NSLog(@"We downloaded video %@", [anObject valueForKey:@"name"]);
          } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
              NSLog(@"Error downloading video %@: %@", [anObject valueForKey:@"name"], error);
          }];
          [videoOperations addObject:opVideo];
      }
  }
  
  [op addDownloadStream:[NSOutputStream outputStreamToFileAtPath:filePath append:YES]];
  
  [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
      ZipArchive *zipArchive = [[ZipArchive alloc] init];
  
      if([zipArchive UnzipOpenFile:filePath]) {
          if ([zipArchive UnzipFileTo:htmlContent overWrite:YES]) {
              //unzipped successfully
              [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
              NSString *htmlContentPath = [htmlContent stringByAppendingPathComponent:@"/htmlContent/html/modules/index/index.html"];
              NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
              [defaults setObject:newAppVersion forKey:@"appVersion"];
              [defaults setObject:htmlContentPath forKey:@"htmlContent"];
              [defaults synchronize];
          } else {
              NSLog(@"Failure To Unzip Archive %@", filePath);
          }
      } else  {
          NSLog(@"Failure To Open Archive %@", filePath);
      }
  } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
      NSLog(@"%@", error);
  }];
  
  for(id opVideo in videoOperations) {
      [engine enqueueOperation: opVideo];
  }
  [engine enqueueOperation: op];
  
  return op;
  </code></pre>
  
  <p>In the view where I want to use this I do:</p>
  
  <pre><code>    self.updateOperation = [ApplicationDelegate.internetUpdater checkAndUpdate];
  
      [self.updateOperation onDownloadProgressChanged:^(double progress) {
          pb.progress = progress;
      }];
  
      [self.updateOperation addCompletionHandler:^(MKNetworkOperation *completedOperation) {
          bottomLabel.text = @"Done";
          [UIView animateWithDuration:0.6
                                delay: 1.0
                              options: UIViewAnimationOptionCurveEaseIn
                           animations:^{
                               v.alpha = 0;
                           }
                           completion:^(BOOL finished){
                               [parentV removeFromSuperview];
                           }
           ];
  
          [self.delegate loginViewControllerDidFinish:self];
          [self dismissModalViewControllerAnimated:YES];
      } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
          NSLog(@"%@", error);
      }];
  </code></pre>
  
  <p>It will always run this Completion Block, even when the movies are still downloading.
  Any hints on why this is not working as I expect? Or do I interpret the dependencies wrong ?</p>