View selector return value when debugging in Xcode

I am running an iPhone development tutorial and I have a strange error that I am investigating with the debugger. I have the following code that checks if an object is within bounds. I'm trying to figure out that the value of ball.center.x is at a specific point, but since the center is the property access selector, I don't get the value when I find it in the Xcode debugger.

if (ball.center.x > self.view.bounds.size.width || ball.center.x < 0) {
    ballVelocity.x = -ballVelocity.x;
}

      

Is there a way to do this? I think I just need to be missing something. I'm guessing that I could update the code to assign a value to a variable that I could observe in the debugger, but that seems like a sloppy work around a common problem.

Thank!

+2


source to share


4 answers


and then also the venerable quick and dirty:



if (ball.center.x > self.view.bounds.size.width || ball.center.x < 0) {
    NSLog(@"ball center: %d",ball.center.x);
    ballVelocity.x = -ballVelocity.x;
}

      

+2


source


I assume the center is CGPoint.

In addition to the Xcode GUI debugger, there is also a gdb prompt when debugging. Try the following:

p* ball

      



or

p ball.center

      

+2


source


Try running gdb command :

p (CGPoint)[ball center] 

      

I am using this trick with UIView.frame, it works.

+2


source


There is an even easier way to do this than using the gdb console. From the main menu select:

Run -> Variables View -> View in expression window

      

And in the expression box text box enter:

(CGPoint)[ball center]

      

The main problem with expression windows displaying an "out of scope" error is almost never knowing the return type of a function (or method), so it doesn't know how to represent the return variable. Apple is letting us know what to do, these are the cases here in the Tips for Using the Expressions Window.

0


source







All Articles