How to print out a property's contents using Xcode debugger?
Once you place a breakpoint, run, and the program stops at the breakpoint, hover your cursor over the variable/value you want to see like this:
You could also place an NSLog(@"%@", yourLabel.text);
to view the contents of that label/other object type.
One other option is to run GDB in the console like this:
gdb
attach <your process name>
And then use the po
(print-object) command to view the value of a variable like this:
po variableName
To view the value of primitive types (int
, float
, long
, double
, char
, etc.), you can just use the print
command while running GDB in the console like this:
print yourPrimitiveVariable
Hope this helps!
EDIT:
With the po
command, you can print out the value of an object using both the property name (self.myProperty
) or the ivar name (possibly _myProperty
). I demonstrate this here:
How can I view the values inside an object in the Xcode debugger?
It's frustrating. The debugger has to know the structure of every object and it apparently doesn't. It used to be much worse, though. Like with NSArray's, they're an array of objects. The debugger doesn't know what type of objects specifically, and that's due to the Objective-C language, not the debugger.
As you dive into iOS development, I think you're going to find that Apple is about 15 years behind its competitors when it comes to development. That's no joke. But they're catching up and, trust me, it used to be much worse!
Inspecting the contents of an array in the Xcode debugger
If it is in scope you can just type
po newArray
into the debugger and it will print the description.
Or if you prefer clicking things then just right click the object in the left panel pof the console and then click "Print Description of ..."
How to see the value of an object property in Xcode at a breakpoint
Modern versions of Xcode use LLDB.
The easiest way to inspect scoped variables during a breakpoint is to use the "Variables View" from within the Debug Area: View > Debug Area > Show Debug Area and then click the "Show Variables View" button (i.e., second-to-last icon in the lower right-hand corner). You can then explore the tree of variables in scope.
Optionally (though I've personally had varied success) you can simply hover your mouse cursor over the variable in question and Xcode should pop up a tool tip with some options.
You can also issue LLDB commands from the console itself. To print out your variable, execute the following command:
print [_moving speed]
Here's a handy list of LLDB commands and their older GDB counterparts.
Xcode Debugger: view value of variable
Check this How to view contents of NSDictionary variable in Xcode debugger?
I also use
po variableName
print variableName
in Console.
In your case it is possible to execute
print [myData objectAtIndex:indexPath.row]
or
po [myData objectAtIndex:indexPath.row]
View object/property state in Xcode while debugging
The instances are actually providing that information themselves. You need to implement the description
method, which is inherited from NSObject
, for your custom classes in order for them to be able to print themselves as something other than a memory address (which is what NSObject
's implementation does).
I've no idea what properties your Hours
class has, but this is as simple as something like:
- (NSString *)description
{
return [NSString stringWithFormat:@"Open: %i Close: %i", self.openTime, self.closeTime];
}
The method just needs to return an NSString
containing whatever information you think is important to see when inspecting the object.
This is also how classes represent themselves when you use the %@
format specifier in NSLog()
.
tips on watching variables or examining objects in Xcode debugging
As you pointed out, there are some GDB commands to enlighten your life.
Print Object:
po objectName
Is probably the most used command to help you with debugger inside Xcode. Here's a roundup on GDB commands inside the Xcode debugger : Debugging tips for Objective-C programming
Personally I kind of rely on the old-fashioned print statements using NSLog. It really is a pain to use the GDB commands all the time.
To me things are faster when I can just print the object and actually see what's going on every time I run the application:
NSLog(@"%@", [info valueForKey:key]);
Here are some tips on using NSLog with parameters: CocoaDev: NSLog
Downpoint: I have to clear out the NSLogs once the app is going to be released.
To your second rather odd iTunes question: Have you enabled accessibility mode on your Mac? (Just a guess, I have never come across something like that)
Related Topics
Code Signing Issue in Xcode Version 8
iOS Lazy-Loading of Table Images
iOS 11 - Unable to Change Navigation Bar Height
How to Take Uiimage of Avcapturevideopreviewlayer Instead of Avcapturephotooutput Capture
Custom Uisearchbar with Uisearchcontroller
Making Uitableview with Embedded Uicollectionview Using Uitableviewautomaticdimension
Xcode 4.2 Mainstoryboard Not Found
Expired Access Token After Openactivesession for Facebook iOS Sdk
iPad 3 - Opengl Bug with Keagldrawablepropertyretainedbacking and Retina
Iphone:Get the File Path Which Is Within Subfolder of Resource Folder
How to Take a Snapshot of a Uiview That Isn't Rendered
Multiple Localized .Strings Files in iOS App Bundle
Setting a Rotation Point for Cgaffinetransformmakerotation Swift
Drawing a Polygon with One Color for Stroke, and a Different One for Fill