简体   繁体   English

如何在XCode调试器中调试NSManagedObjects?

[英]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? 在XCode调试器中,如何获得实体(NSManaged Object的子类)的值? I get lost among the NSObject and _cd_XXX structures. 我迷失在NSObject和_cd_XXX结构中。

如果在变量窗格中选择实体,然后从上下文菜单中选择“将描述打印到控制台”,则会获得实体的文本转储。

In the Debugger Console type 在Debugger Console类型中

po [your_entity your_property]

I don't really know another useful way, as the entity may eg be faulted and also the NSManagedObject structure isn't really helpful, as you already noticed. 我真的不知道另一个有用的方法,因为实体可能会出现故障,并且NSManagedObject结构也没有真正有用,正如您已经注意到的那样。

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. 您也可以在调试器中键入p <expression>以达到类似的效果。 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 (eg, 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. 如果你正在处理一个无差别的NSObjectNSManagedObject或类似的东西,那么这可能有点痛苦,你可能想要转储表达式,如其他答案中所述,但如果对象确实有一个合适的接口(例如,变量具有NSObject类型但对象具有更具体的类)然后在调试器中将其强制转换通常会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM