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

swiftd

macrumors newbie
Original poster
Jul 12, 2009
11
0
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!!
 
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:
Code:
 ((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)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.