Array error

Discussion in 'iOS Programming' started by swiftd, Jul 27, 2009.

  1. swiftd macrumors newbie

    Jul 12, 2009
    Hey guys. Why is it that this will work:

    tile1.image = [characterToTile characterImage];

    but this doesn't? (please note I pass the value 1 as the position parameter):

    NSArray *characterArray = [[NSArray alloc] initWithObjects: tile1, tile2, nil];
    -(void)putCharacter: (Character)characterToTile onTile: (NSInteger) charPosition {
    [characterArray objectAtPosition:charPosition].image = [characterToTile characterImage];​

    I don't have the compile error in front of me but it's the one about request for member in something not a structure or union. Any help would be greatly appreciated!!
  2. moral-hazard macrumors regular

    Jul 27, 2009
    Palo Alto, CA
    Try casting it. The compiler doesn't know what type of object to expect out of the array, so it can't possibly know that it will respond to your property getter (the ".image")

    The cast would look like this:
     ((ClassName *)[characterArray objectAtPosition:charPosition]).image 
    Where "ClassName" is whatever class of object it is that is coming out of the array (i.e. the object at the position you are specifying)
  3. swiftd thread starter macrumors newbie

    Jul 12, 2009

Share This Page