Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nnavick

macrumors regular
Original poster
Oct 13, 2010
100
0
Hi All,
I tried to add NSInteger into my NSMutableArray and it's writing a warning


the code is

.h File
Code:
NSMutableArray *CellsNumber;
NSInteger *Number;


.m File
Code:
       CellsNumber = [[NSMutableArray alloc] init]; 
       NSInteger *myInt;
	myInt=(arc4random()% 50);
	for(int i = 0 ; i <[CellsNumber count] ; i++) {
		Number=[CellsNumber objectAtIndex:i][COLOR="blue"]warning: assignment from incompatible pointer type[/COLOR]



		if(myInt==Number)  [COLOR="blue"]warning: comparison between pointer and integer[/COLOR]



		myInt=(arc4random()% 50);	
	}
        [CellsNumber addObject:myInt]; [COLOR="blue"]warning: passing argument 1 of 'addObject:' makes pointer from integer without a cast[/COLOR][/QUOTE]

what is the problem?
Thanks
 

ulbador

macrumors 68000
Feb 11, 2010
1,554
0
Hi All,
I tried to add NSInteger into my NSMutableArray and it's writing a warning

NSInteger isn't a real object. It is simply a synonym for a long. This is how it is defined on a 64 bit system:

typedef long NSInteger;


an NSMutableArray expects objects. An "int" is not an object, it's a primitive. To put a number in an array, use NSNumber and the numberWithInt method.

Also, when you pull it out for comparisons, you have to convert it back to a primative:

int myNumber = [[myArray objectAtIndex:i] intValue]; // assuming you've loaded a NSNumber
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.