'左操作数'中的'垃圾值'是什么?'是'生成和分析'生成的垃圾值'警告?

Mic*_*est 6 xcode cocoa-touch objective-c ios

当我在Xcode中"构建和分析"这段代码时,我收到一条我不明白的警告.这是带问题的方法:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch * touch = [touches anyObject];
        CGPoint location = [touch locationInView:self];
        CGPoint relativePosition = CGPointMake(1.0-(location.x / self.bounds.size.width),location.y / self.bounds.size.height);
        [[Stage getSharedStage] movePartToLocation:relativePosition];
}
Run Code Online (Sandbox Code Playgroud)

这是警告:

 warning: The left operand of '/' is a garbage value
         CGPoint relativePosition = CGPointMake(1.0-(location.x / self.bounds.size.width),location.y / self.bounds.size.height);
                                                     ~~~~~~~~~~ ^
1 warning generated.
Run Code Online (Sandbox Code Playgroud)

这是箭头: 替代文字

它试图告诉我什么?代码工作正常.

Fer*_*cio 6

在没有看到整个函数的情况下很难分辨,但我认为这意味着代码可以采用的路径,其中location.x永远不会被初始化.可能是代码从未在测试中采用该路径,但可能存在.

编辑:我将在这里做一个疯狂的猜测,并说这是因为[触及anyObject]可以想象回来nil.在这种情况下[touch locationInView:self]将返回垃圾(记得发送消息nil是完全有效的).

尝试使条件的其余部分成为条件(touch != nil).