开发者

How to evaluate/watch a variable or method whilst debugging in XCode

I come from a Delphi and .Net background and have just started iPhone development. I just came across a problem whilst debugging.

I had the following code:

if ([displayText rangeOfString:@"."].location != NSNotFound) .....etc

I wanted to evaluate this whilst I was debugging but could not work out how to do it. I found the Expressi开发者_如何学JAVAons window and entered the below but nothing happened:

[displayText rangeOfString:@"."].location

As I'm used to Delphi & .Net (and I know XCode is a different product) its very easy to stick in variables, methods etc into a watch window and then see the result but I cannot see how to do this in XCode. Please can you tell me how I evaluate things whilst debugging??

Thanks


In your case, what you would do is at the debugger is type:

p (NSRange)[displayText rangeOfString:@"."]

You can print out the value of objects with po, but things like C structures have to be printed out with "p" and you have to cast the return types from ObjC calls to the correct struct type.

Also, just putting this in the Expressions window should result in a value:

(NSRange)[displayText rangeOfString:@"."]

In both cases you will see the whole NSRange struct, with location and length.


You can watch variables by going in the debugging drop down in the main menu on top and selecting watch variable. You can also right click and you should see the option "watch variable." Alternatively you can hover your mouse over the desired variable while stepping through your code to see its value at that time

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜