understanding Xcode debugger var display - xcode

newbie question: can anyone tip me to how to understand/interpret what is displayed in the debugger var pane?
Ex: I am passing an NSDictionary as a method param. I set a breakpoint so I can examine the values in the dictionary. The image below (if it comes through..) shows the expanded view of this var in the debugger. It correctly reports that it contains 3 name/value pairs but as I expand all the sections, I simply can not find where these are stored.
Do I have to create local vars of these name/value pairs in order to view them when I want to check? I know I can use NSLog or printf but sometimes I just want a quick peek.

Right click the variable, click "Edit Summary Format" and type the following:
{(NSString*)[$VAR description]}:s
This replaces the GDB formatter for NSDictionary with a call to the more expensive description method.
That is, instead "x key/value pairs", you'll see the contents of the dictionary as produced by -[NSDictionary description].
This is the same as typing po dictionary in the console window. Or right clicking the variable and choosing "Print Description". Both of them call the description method of the object.
If you are curious, you can find this formatter at /Developer/Library/Xcode/CustomDataViews/Foundation.plist under the key NSDictionary. What you type as replacement is saved in /Users/USERNAME/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters and will persist across runs until you delete that file.
A NSDictionary is really a class cluster and few people know the inside structure. At this point you ain't going to find much use for that debugger tree.

This is what you are looking for :
Click on your dict, then click on the little "i" icon :-)

Related

Viewing complex objects in debugger

Is it possible to construct custom views for complex objects?
Specifically I want to view the inner workings of a CGPath.
I've found the "view variable as" option with right clicking the variable in the debug view, and I've seen ways to view (eg) strings &tc with it, but I haven't found anything that helps me in this case.
po path in the debugger will print out all of the path's elements. UIBezierPath has quick look support in the debugger, where you can hit space and view a drawing of it, but you have a CGPath. It seems that quick look support is not enabled for CF classes like CGPath.
But you're not stuck. If you right-click the variables list in the debugger (as shown here), and choose add expression, you can create a local UIBezierPath by typing this in the expression field:
UIBezierPath(cgPath: path)
or, if your debugger is in an Objective-C context:
[UIBezierPath bezierPathWithCGPath: path]
Your expression then shows up in the list, and you can press the space bar to see a visual representation.
This example shows how I have it set up in an Objective-C project:
Quick-looking the path shows this:
If po path isn't showing you any components (moveto, curveto etc) in the debugger, then I think you have an empty path, and your problem lies elsewhere. If otherPath is nil, then I get an invalid expression in the debugger when creating the bezier path.

How to avoid watch list variable to collapse on value change in Visual studio?

I would like to avoid that the watch window collapse my list variable content on value change during the process of my application in debug mode. I don't know if i'm really clear, see pictures below:
Collapsed:
Expended:
I would like to see the content of my list and let the content of my list expanded even if a string of my list change. Is there a way to lock the watch window?
As #JasonH mentioned, list will stay expanded while variable references same object and watch will show modified element in red color. List will collapse when you assign new reference to a variable. I am not aware of any option to change this behavior.
As an alternative, you can pin items in a list you are interested in. Or you can pin all items. In this you will get list expanded event if reference changes. But It will be available only in this concrete tab. Here is an example and picture of each step:
var ints = new [] {"1", "2", "3", "4"};
ints[1] = "3";
ints = new[] { "1" };
The short answer to 'pinning a watch item open' is no, you cannot.
First, this option is just not available in VS but you can suggest it at Visual Studio User Voice if you feel that it would help you and others.
Second, and this gets a bit complicated but follow with me...
If the watch item goes out of scope, it will collapse. If the watch item is re-initialized (which in a way kind of takes it out of scope for a moment) it will also collapse. If you have a watch item (complex object) and you start changing its properties and/or fields, you will see that they (the properties and fields) will change but the watch item (object) does not collapse.
I hope this helps.

Search for an NSView inside a NIB by string

I'm trying to write an application which should display some data. The data in question comes from a different module in our code (written in C, not ObjC), and for various reasons is identified by a string, not an integer or other form of constant. After the glue code, I have an incoming method on my AppDelegate like so:
-(void)newstringdata:(NSString*)data withLabel:(NSString*)label;
This method should always take the value of data and set it as the text for a particular label in the UI. The problem is, which label.
I could of course create an NSDictionary and fill it at run time with the possible values for the label parameter in the newstringdata:withLabel: method and references to outlets, but this seems somewhat ugly and inefficient; it requires me to maintain the outlets, the nib, and the NSDictionary-initializing code.
Instead, if possible, I would like to set a property in the interface designer somewhere, and then do a lookup in my newstringdata:withLabel: method based on the label which was passed which returns the NSLabel.
Is this possible? If so, how would I do it?
If the value of label will never include a slash (/), backslash (\), or colon (:), you can use the identifier property of NSView.
In the xib, enter each label string as the NSTextViews's identifier (in the Identity tab, 3rd tab from left).
Then in your code, loop through all views and:
if ([aView.identifier isEqualToString:label])
[aView setStringValue:data];

NSTextView / NSScrollView - A few questions to help me understand it's proper usage

I have created a "notes" field designed to hold multiple paragraphs of text which I would like to store in a custom object. Originally, I just used an NSTextField as a temporary solution, but this does not allow me to scroll or have multiple paragraphs of text...
In IB I have placed a NSTextView (which seems to be wrapped inside an NSScrollView.) Upon execution of my program, seems to allow me to enter text in multiple paragraphs, scroll, etc. In short it LOOKS to be exactly what I want would like it to be. So far so good.
Now, I need to retrieve the data from this field and store it in my custom object. This is where I'm getting a bit lost within the developer documentation...
My goals are fairly straight forward:
Allow users to type away in the box.
Store the contents of the box into a variable (array, etc.) in my custom object when the user moves to another field, leaving the notes field.
Display the users stored text in the text box next time the record is viewed.
Second, is there a simple way to retrieve and store the data into a "notes" variable in my custom object (such as an NSString object? I would think having multiple would exclude an NSString object as an option here, but maybe I'm wrong) or am I getting into a more complex area here (such as having to store it in an array of NSString objects, etc.)?
Any help would be appreciated!
You can get the data using -string, defined by NSText (e.g. NSString *savedString = [aTextView string])
Your save code can be put in your NSTextDelegate (read, delegate of the NSTextView, because it's the immediate superclass), in – textDidEndEditing: which will be called, well, when editing is finished (e.g. when the user clicks outside the view) or one of the other methods.
Then to reload the saved string if you emptied the text view or something, use [textView setString:savedString] before editing begins.
NSTextDelegate documentation: here.
I'm not sure what you mena when you say "store the contents of the box into a variable (array, etc.) Are you hoping for an array of custom notes? Text views store a string of data, so the easiest way of storing its value is using one string; if you need an array of notes you'd have to split the string value into different paragraphs, which shouldn't be too hard.

Xcode debugging: View value of NSNumber?

Is it possible to see the numeric value of an NSNumber in the debugger datatip on in the variable watch window?
I store an Integer value in NSNumber and want to see this value during debugging.
I tried some of the data formatters in the debugger already, but it wasn't much help.
Open the Debugger view and in the Summary column enter
{(int)[$VAR intValue]}
or whatever interpretation is most appropriate for what you want to see in the Debugger.

Resources