How can I debug NSManagedObjects in XCode debugger? How can I debug NSManagedObjects in XCode debugger? xcode xcode

How can I debug NSManagedObjects in XCode debugger?


If you select the entity in the variables pane and then choose "Print Description to Console" from the contextual menu, you get a textual dump of the entity.


In the Debugger Console type

po [your_entity your_property]

I don't really know another useful way, as the entity may e.g. be faulted and also the NSManagedObject structure isn't really helpful, as you already noticed.


Go into the debugger window, right-click, "Add Expression..." and type in the expression as it would appear in the code; you can also type p <expression> in the debugger to similar effect. For example in my case:

managedObjectContext.registeredObjects.first?.value(forKey: "shifts") as? [Shift]

If you're dealing with something which is an undifferentiated NSObject or NSManagedObject or similar then this can be a bit of a pain and you may want to dump the expression as described in the other answers here, but if the object does have a proper interface (e.g., the variable has a type of NSObject but the object has a more specific class) then casting it in the debugger would generally do nicely.