Objective-C のブロックについて質問があります。
たとえば、次のコードがあります。
__block int count = 0;
void (^someFunction)(void) = ^(void){
count = 4;
};
count +=2;
カウントが 2 ではなく 6 になるように、同じコードを記述する適切な方法は何でしょうか?!
ありがとうございました!
私の前の質問はぼやけていたので、おそらく実際のコードを表示する必要があります。編集:
__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;
10回の反復後、カウントが0になる...なぜ?!?!