I am simply trying to add a series of numbers to an NSMutableArray
but I am getting the error:
implicit conversion of int to id is disallowed with arc
resultArray = [[NSMutableArray alloc]init];
for (int i = 0; i <= 9; i++)
{
[resultArray addObject:i];
}
What am I doing wrong?
An NSArray
or NSMutableArray
can only hold objects, not primitive data types such as int
s. So if you want to add them to the array, you'll have to wrap them in an NSNumber
. You can do the following:
[resultArray addObject:@(i)];
This is equivalent to doing:
[resultArray addObject:[NSNumber numberWithInt:i]];
来源:https://stackoverflow.com/questions/21888463/trying-to-populate-nsmutablearray-but-get-implicit-conversion-of-int-to-id-is-di