在我的previous question中,我问为什么我的申请提前终止。事实证明我在下面的一行中得到了这个警告,这可能有助于我解决我的问题。
以下是代码:
NSMutableArray *redValues = [NSMutableArray array];
NSUInteger redValuesLength = [redValues count];
float totalOne, diffForAverage;
int amount = 1;
__block int counter = 0;
NSInteger j;
GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
GPUImageAverageColor *averageColor = [[GPUImageAverageColor alloc] init];
[averageColor setColorAverageProcessingFinishedBlock:^(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime)
{
NSLog(@"%f", redComponent);
[redValues addObject:@(redComponent * 255)];
}];
[videoCamera addTarget:averageColor];
[videoCamera startCameraCapture];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 27 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[videoCamera stopCameraCapture];
});
totalOne = [redValues[25] floatValue];
float average = totalOne / amount;
for (j = (counter + 25); j < (redValuesLength - 25); j++)
{
diffForAverage = average - [redValues[j + 1] floatValue];
if (diffForAverage > -1 && diffForAverage < 1)
{
totalOne += [redValues[j + 1] floatValue];
amount++;
[arrayOne addObject:[NSNumber numberWithInt:(j - 25)]];
counter++;
}
else
{
if (arrayOneLength >= 15)
{
break;
counter++; // WARNING OCCURS HERE
}
else
{
[arrayOne removeAllObjects];
totalOne = [redValues[j + 1] floatValue];
counter++;
}
}
}
为什么上面的注释行永远不会被运行?这是我的for循环问题,还是我的if语句,还是完全不同的东西?
答案 0 :(得分:4)
因为你之前有一个break
命令。 break
命令会立即将您带出for
循环,因此下一行不会被执行。