This is my first post, so be kind 🙂
I’ve looked around for solutions but can’t seem to find one. Problem may be asking the question in a way that google will return useful results.
So, I have an NSMutableArray (called boardColCoords), and I have CGPoint (called touchLocation). I want to compare the two so that I can snap a UIImageView location to the proper coordinate in the boardColCoords array.
Here’s the relevant code:
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
NSNumber *boardSquareX = [boardColCoords objectAtIndex:i];
if (touchLocation.x - boardSquareX <= 12)
{
}
I know that 12 will eventually have to be changed, but I just want to get the subtraction working first. The specific error I get is:
Invalid operands to binary expression (‘CGFloat’ (aka ‘float’) and “NSNumber *).
NSNumber is a wrapper, you have to “extract” it’s value with something like
floatValueto compare like that: