Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print an object's property to the Debugger Console in Xcode?

I have an object that was created with the Core Data code generator:

.h file:

@interface MyObject :  NSManagedObject  
{
}

@property (nonatomic, retain) NSString * title;
@end

.m file:

@implementation MyObject
@dynamic title;
@end

I put a breakpoint and now I want to print the title property of one of its instances (myObject) to the console.


When I try po myObject.title, I get the error:

There is no member named title.

When I try po [myObject title], I get the error:

Target does not respond to this message selector.

When I try myObject.title in the Expressions window, I get the error:

out of scope

... even though myObject in the same window allows me to see some of its members.


How can I print an object's property to the console and/or Expressions window in Xcode?

like image 722
Senseful Avatar asked Aug 23 '10 14:08

Senseful


People also ask

How do I print a variable in Xcode?

Print a variableClick the Add Action button and select Debugger Command. Put any print command in a debug console in a text field. Make sure you prefix it with po , e.g., po print(view) . Check Automatically continue after evaluating actions.

How do I print from Xcode?

How to print () to Xcode console in SwiftUI ?, Try right-clicking on the live preview play button and selecting 'Debug Preview from the popup. The print function prints messages in the Xcode console when debugging apps.

How do you print an object in Swift?

Writing Output with print() You use the print() function in Swift to write a string to standard output, which is typically the Console in Xcode. Here's an example: print(“So long and thanks for all the fish!”) The above example can't get any easier.

Where are print statements in Xcode?

Press ⇧⌘Y or choose View > Debug Area > Show Debug Area to show the console output (or ⇧⌘C / Activate Console). Usually, this window will open automatically when your program produces output (this is controlled by the Behaviors section of Xcode's Preferences). Save this answer. Show activity on this post.


1 Answers

You can get around this by using valueForKey -

po [myObject valueForKey:@"title"]

which gets tiresome pretty quickly, but works ok.

like image 153
Jonathan del Strother Avatar answered Oct 13 '22 00:10

Jonathan del Strother