从不兼容的类型'id'分配给'float'

时间:2017-01-12 03:22:51

标签: objective-c

以下评论的两行发生以下错误:

  

从不兼容的类型'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++;
        }
    }
}

为什么会导致此错误,我该如何解决?

1 个答案:

答案 0 :(得分:2)

totalOne是浮动的。你的数组持有NSInteger。改为:

totalOne = [redValues[25] floatValue];
相关问题