比较CGPoint和NSNumber

Jam*_*son 1 iphone xcode objective-c

这是我的第一篇文章,所以要善待:)

我四处寻找解决方案,但似乎无法找到解决方案.问题可能是以谷歌将返回有用结果的方式提出问题.

所以,我有一个NSMutableArray(称为boardColCoords),我有CGPoint(称为touchLocation).我想比较两者,以便我可以将UIImageView位置捕捉到boardColCoords数组中的正确坐标.

这是相关的代码:

UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];

NSNumber *boardSquareX = [boardColCoords objectAtIndex:i];

if (touchLocation.x - boardSquareX <= 12)
{
}
Run Code Online (Sandbox Code Playgroud)

我知道12最终将不得不改变,但我只想让减法先行.我得到的具体错误是:

二进制表达式的操作数无效('CGFloat'(又名'浮动')和"NSNumber*").

Emi*_*aez 8

NSNumber是一个包装器,你必须"提取"它的值,比如像floatValue这样比较:

if (touchLocation.x - [boardSquareX floatValue] <= 12)
Run Code Online (Sandbox Code Playgroud)