views:

52

answers:

1

When I 'Build and Analyze" this code in Xcode, I get a warning that I don't understand. Here's the method with the problem:

-(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];
}

Here's the warning:

 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.

Here are the arrows: alt text

What is it trying to tell me? The code works fine.

+1  A: 

It's hard to tell without seeing the entire function, but I would take that to mean that there exists a path the code could take where location.x is never initialized. It may be that the code never takes that path in your testing, but the possibility is there.

EDIT: I'm going to take a wild guess here and say that it's because [touches anyObject] could conceivably return nil. In which case [touch locationInView:self] will return garbage (remember sending messages to nil is perfectly valid).

Try making the rest of the function conditional on (touch != nil).

Ferruccio
I was thinking along the same lines. What is touch defined as?
CiscoIPPhone
I've expanded to show the whole method. Could it be something to do with using [touches anyObject]?
Michael Forrest