iOS: How to watch NSManagedObject attributes while debugging

前端 未结 1 1867
抹茶落季
抹茶落季 2021-02-08 14:23

As the title said, I want to debug some Core Data bugs. Instead of using NSLog everywhere in the code, is it possible to watch a entity\'s attributes in XCode 4\'s

相关标签:
1条回答
  • 2021-02-08 14:54

    Any value that has a named variable assigned to it can be viewed in the debugger. In Xcode 4 it appears in the debugger's left column. If you select the variable, you can use the contextual menu option "Print to console" to have a detailed description printed to the debugger console. This is useful when examining managed objects as they often contain more info than the list of variables can cleanly display.

    (See- Xcode 4 Transition Guide:Control Program Execution in the Debug Area and Source Editor, Figure 5-9

    In addition, you can issue any of the standard gdb commands from the command line in the debugger console. The most useful of the these commands is po which stands for print object. Say you have an object myObject that has a property aProperty. You could examine it directly by using:

    po [myObject valueForKey:@"aProperty"]
    

    If you create NSManagedObject subclasses, you also have the option of overriding the description method which allows you to produce custom descriptions of the object which will show up in print to console and the po command.

    0 讨论(0)
提交回复
热议问题