Xcode Debugger: View Variable Value

My code in UITableViewController:

delegate.myData = [myData objectAtIndex:indexPath.row]; 

How can I see delegate.myData or indexPath.row in the debugger? delegate.myData must be an array and indexPath.row a int . I can only see the memory addresses of the delegate and indexPath , but where is myData and row ?

alt text

+85
debugging ios objective-c iphone xcode
Jan 19 '11 at 12:22
source share
7 answers

Check How do I view the contents of an NSDictionary variable in the Xcode debugger?

I also use

 po variableName print variableName 

in the console.

In your case, you can run

 print [myData objectAtIndex:indexPath.row] 

or

 po [myData objectAtIndex:indexPath.row] 
+101
Jan 19 '11 at 3:15 a.m.
source share

You can also:

  • Set a breakpoint to pause execution.
  • The object must be inside the execution area
  • Move the mouse over an object or variable
  • A yellow prompt will appear.
  • Mouse over tooltip
  • Click on the two small arrows pointing up and down
  • A context menu will appear.
  • Select "Print Description", it will execute the description [object description]
  • Description will appear on console output

IMHO a little hidden and bulky ...

+19
Feb 17 '12 at 19:21
source share

I agree with other posters that Xcode as an evolving environment should include an easy way to debug variables. Well, good news, there is one!

After searching and not having a simple answer / tutorial on how to debug variables in Xcode, I went on to research with Xcode itself and found this (at least for me) a very useful discovery.

How to easily debug variables in Xcode 4.6.3

On the Xcode main screen, make sure you see the bottom debug area by clicking the top corner button shown in the screenshot.

Debug area button

Debug Area in Xcode 4.6.3

Now set a breakpoint - the line in the code where you want to pause your program by clicking on the border of your code area.

Breakpoint

Now in the debug area, find these buttons and click on the center in the middle. You will notice that your area is now divided into two parts.

Split Debug Area

Should look like this

Now run the application.

When the first breakpoint is reached during the execution of your program, you will see on the left side all of your variables available at that breakpoint.

Search field

You can expand the left arrow on a variable for more detail. And even use the search box to isolate this variable that you want and see how it changes in real time when you โ€œenterโ€ the breakpoint area.

Step into

On the right side of the debugging area, you can send to print the variables as you wish, using the right-click on the desired variable.

Contextual Menu

As you can see, this context menu is filled with very interesting debugging options. For example, Watch, which has already been proposed using typed commands, or even Edit Value ..., which changes the runtime value of your variable!

Ok, hope this helped you. Please vote!

+17
Jul 23 '13 at 17:05
source share

Your confusion stems from the fact that declared properties are not (necessarily called the same as) (instances) variables.

Expression

 indexPath.row 

equivalently

 [indexPath row] 

and assignment

 delegate.myData = [myData objectAtIndex:indexPath.row]; 

equivalently

 [delegate setMyData:[myData objectAtIndex:[indexPath row]]]; 

assuming standard naming for synthesized properties.

In addition, the delegate is probably declared as a type of type id<SomeProtocol> , i.e. the compiler was unable to provide actual type information for the delegate at this point, and the debugger relies on the information provided at compilation time. Since id is a generic type, there is no information about the compilation time of instance variables in delegate .

That is why you do not see myData or row as variables.

If you want to check the result of sending -row or -myData , you can use the p or po commands:

 p (NSInteger)[indexPath row] po [delegate myData] 

or use the expression window (for example, if you know that your delegate is of the actual type MyClass * , you can add the expression (MyClass *)delegate or right-click the delegate , select View Value asโ€ฆ and enter the actual delegate type (for example, MyClass * ).

However, I agree that a debugger might be more useful:

  • In the debugger window, you may be able to use information such as run-time, rather than compile-time information. This will slow down the debugger, provide but provide useful information;

  • Declared properties can appear in a group called properties and allow (optional) verification directly in the debugger window. It will also slow down the debugger due to the need to send a message / execute a method to get information, but also provide useful information.

+9
Jan 19 2018-11-11T00:
source share

You can print values โ€‹โ€‹in the console window at run time. Following are the steps:

  • Place a breakpoint for which you want to get values
  • Now do a step-by-step debugging.
  • Place the cursor on a variable / delegate whose value should be checked at runtime.
  • Now it will show the description of the variable / delegate
  • By clicking on "i" you will see a detailed description
  • It will also print information in the console window.

Screenshot for printing details on console window

+6
Aug 25 '14 at 14:34
source share

This gets a little complicated. These objects are custom classes or structures, and looking inside them is not as easy in Xcode as in other development environments.

If I were you, I would NSLog the values โ€‹โ€‹you want to see with some description.

i.e:

 NSLog(@"Description of object & time: %i", indexPath.row); 
+1
Jan 19 '11 at 12:51
source share

Try Run-> Show-> Expressions

Enter the name of the array or whatever you are looking for.

+1
Jan 19 2018-11-11T00:
source share



All Articles