objectAtIndex won't work for an array of NSNumbers

12 Views Asked by At

I have two arrays. The first is called "tiles" and has say 10 pictures, the second is called "shuffledTiles" and has say 10 numbers. The "tiles" array has been initiated using the normal "init with objects", like so:

self.tiles = [[NSMutableArray alloc]initWithObjects:

[UIImage imageNamed:@"firstImage.png"],
[UIImage imageNamed:@"SecondImage.png"],

etc...

and the shuffledTiles has been created with a for loop that added a number per picture like so:

int tileCount = [self.tiles count];

  for (int tileID = 0; tileID < (tileCount); tileID++)
  {
    [self.shuffledTiles addObject:[NSNumber numberWithInt:tileID]];
   }

I am now trying to log out the result of both arrays with another for loop

  for (int i = 0; i < tileCount; i++){
        NSLog(@"%@", [self.tiles objectAtIndex:i]);
        NSLog(@"%@", [self.shuffledTiles objectAtIndex:i]);

and the compiler fails. If I comment out the second NSLOG:

// NSLog(@"%@", [self.shuffledTiles objectAtIndex:i]);

it works fine. So, my question is: why does the method "objectAtIndex" work with an array of pictures but not with an array of NSNumbers?

Thanks,

0

There are 0 best solutions below