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?
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 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.
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.
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.
You can get around this by using valueForKey -
po [myObject valueForKey:@"title"]
which gets tiresome pretty quickly, but works ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With