Block von Variablen in Objective-C

Ich habe eine Fragen über Blöcke in Objective-C.

Ich habe zum Beispiel diesen code:

__block int count = 0;
void (^someFunction)(void) = ^(void){
count = 4;
};
count +=2;

Was wäre die richtige Art und Weise zu schreiben, die das gleiche Stück code, so dass die Zählung wird zu 6, nicht 2 ?!

Danke!

Ich sollte wohl zeigen den eigentlichen code, da meine Vorherige Frage war verschwommen.
EDIT:

__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 > 5)
         {
             NSLog(@"here");
         }
         count++;
     }];
     int f = count+1;

nach 10 Iterationen, die Anzahl ist 0...warum?!?!

Schreibe einen Kommentar