Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode debugger vs NSLog - dictionary keys and values

I'm trying to get better at using the debugger rather than just always printing my debugging message out via NSLog. This morning I thought I had a great use for it - to find how the changed values of a KVO dictionary. But when I set a breakpoint just after the appropriate code and ran with debugging on, all I saw in the debugger was this in the summary:

{(int)[$VAR count]} key/value pairs

and expanding the item never gets to any key or value.

But when I print out the "change" dictionary via NSLog I get the key and the value:

[timestamp] appName[3643:707]  observeValueForKeyPath new filePath change: {
kind = 1;
new = foo;

I guess I have two questions:

  1. Is there a way to get dictionary keys and values with the Xcode debugger?
  2. Is there a set of rules of thumb for using the debugger vs printing log messages?

I'm (still) using Xcode 3.2.6.

Thanks!

EDIT: I realize that "foo" is not a valid file path. At this point I'm still testing sending a value around via KVO.

like image 995
Tony Adams Avatar asked Feb 27 '26 23:02

Tony Adams


1 Answers

  1. Set a breakpoint on the spot you want to check the value of the variable and run your application. When the breakpoint gets tripped put your mouse over the variable in the debugger. A little popup should come up, move your mouse over the arrows on the left side and another menu should popup. Click on "Print Description" and it should display something similar to a log in the console. enter image description here

  2. It is just a case by case method but a lot of it is just personal preference. You will just have to find what works for you.

If I am going to check a variable a lot at a one specific point, I will go with a log. It is usually the quickest way to see if something is working right

If I am checking how a part of the code affects a variable I will use the debugger and step through the code. It is also useful for checking the values of lots of variables in a section of code.

like image 56
Justin Meiners Avatar answered Mar 01 '26 14:03

Justin Meiners



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!