title: Block variables in Objective-C
body: <p>I have a questions about blocks in Objective-C.</p>
  
  <p>For example I have this code:</p>
  
  <pre><code>__block int count = 0;
  void (^someFunction)(void) = ^(void){
  count = 4;
  };
  count +=2;
  </code></pre>
  
  <p>What would be the proper way to write the same piece of code so the count will become 6, not 2 ?!</p>
  
  <p>Thank you! </p>
  
  <p>I should probably show the actual code because my previous question was blurry.
  EDIT:</p>
  
  <pre><code>__block CMTime lastTime = CMTimeMake(-1, 1);
      __block int count = 0;
      [_imageGenerator generateCGImagesAsynchronouslyForTimes:stops
                                            completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime,
                                                                AVAssetImageGeneratorResult result, NSError *error)
       {
           if (result == AVAssetImageGeneratorSucceeded)
           {
               NSImage *myImage = [[NSImage alloc] initWithCGImage:image size:(NSSize){50.0,50.0}];
               [arrOfImages addObject:myImage];
           }
  
           if (result == AVAssetImageGeneratorFailed)
           {
               NSLog(@"Failed with error: %@", [error localizedDescription]);
           }
           if (result == AVAssetImageGeneratorCancelled)
           {
               NSLog(@"Canceled");
           }
           if (arrOfImages.count &gt; 5)
           {
               NSLog(@"here");
           }
           count++;
       }];
       int f = count+1;
  </code></pre>
  
  <p>after 10 iterations count is 0...why?!?!</p>