The following error occurs on the two lines that are commented below:
以下注释的两行发生以下错误:
Assigning to 'float' from incompatible type 'id'
从不兼容的类型'id'分配给'float'
NSMutableArray *redValues = [NSMutableArray array];
NSUInteger *redValuesLength = [redValues count];
NSMutableArray *arrayOne = [NSMutableArray array];
NSUInteger arrayOneLength = [arrayOne count];
__block int counter = 0;
int amount = 1;
float totalOne, diffForAverage;
NSInteger j;
totalOne = redValues[25]; // ERROR OCCURS HERE
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++;
}
else
{
[arrayOne removeAllObjects];
totalOne = redValues[j + 1]; // ERROR OCCURS HERE
counter++;
}
}
}
Why is this error caused, and how can I fix it?
为什么会出现此错误,我该如何解决?
1 个解决方案
#1
1
totalOne is float. And your array hold NSInteger. Change to that:
totalOne是浮动的。你的数组持有NSInteger。改为:
totalOne = [redValues[25] floatValue];
#1
1
totalOne is float. And your array hold NSInteger. Change to that:
totalOne是浮动的。你的数组持有NSInteger。改为:
totalOne = [redValues[25] floatValue];