11

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.

3 Answers 3

23

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.

1
  • 1
    not exactly what I was looking for but you got 6 votes and it works as described.
    – KingAndrew
    Feb 18, 2013 at 11:08
10

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.

0
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.