KingAndrew
KingAndrew

Reputation: 1165

How can I debug NSManagedObjects in XCode debugger?

How do you get to the values of your Entity (sub class of NSManaged Object) when in the XCode debugger? I get lost among the NSObject and _cd_XXX structures.

Upvotes: 11

Views: 3967

Answers (3)

Jim Driscoll
Jim Driscoll

Reputation: 904

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.

Upvotes: 1

TechZen
TechZen

Reputation: 64428

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.

Upvotes: 23

Alfonso
Alfonso

Reputation: 8482

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.

Upvotes: 10

Related Questions