iOS: How to watch NSManagedObject attributes while debugging - ios

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 watch window? Like the "quick watch" tool in Entity Framework 4.0 of .NET.

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.

Related

Easiest way to debug objective-c classes in xcode?

I finished writing a class' .h and .m files in objective c in XCode and want to see if all the class functions are implemented correctly. I have not set up anything in the storyboard file yet but would like to test and debug the code. I'm looking to simply declare an object of the class type and to run some of the functions on it similar to using the command line with Python.
If there's no way to simply debug code using command line commands, what would be the easiest way to set up the storyboard?
You can use the XCTest to test your classes.
You can find all the information you need in the Apple documentation is actually pretty easy to use.
https://developer.apple.com/Library/ios/documentation/DeveloperTools/Conceptual/testing_with_xcode/testing_2_testing_basics/testing_2_testing_basics.html#//apple_ref/doc/uid/TP40014132-CH3-SW1
If you want you can check this tutorial as well.
http://rshankar.com/test-driven-development-in-ios-beginners-tutorial-part-1/
If you want you can set break points as well and check that your code is executing properly. Sometimes when I just want to proof-test small classes I do it just setting a couple of break points instead of the XCTest classes but it all depends on your study case. If you have a decent amount of classes I would suggest to use XCTest to check that the classes are actually doing what is expected setting your assertions and the other conditions that XCTest offers as a framework.
Another way you can do your testing if applicable is using NSLog to print in console lines or values of interest at each stage of your code execution.
You mentioned the command line. If you set breakpoints you can use po objName to print the value or print varName to check values of objects and primitive variables correspondingly. po stands for print object and print well... There's different options if you feel comfortable using the console just set NSLogs at certain point of your code or set the break points and print the values using po or print commands in the console.
Here you can check the string format specifiers for NSLog which are the same ones used for NSString
https://developer.apple.com/library/ios/documentation/cocoa/conceptual/Strings/Articles/formatSpecifiers.html

Xcode debug variable and LLDB po dump are inconsistent

I ran into a situation that Xcode shows different result of one object from the result of po command in LLDB. firstly, all values in the object is nil and the object is displayed with *const type modifier, which it shouldn't be. and when I use po to get datasource variable it shows correct data. However, it shows datasource is nil in Xcode variable list.( please see following screenshot) Can anyone explain why?
This seems like the sort of thing you should file a bug with Apple about. Probably take more back and forth to figure out what is going on than can be easily done in this context.

Difference Between Debugger and Target Output in Xcode

When I run my app in Xcode, the output area often becomes cluttered by warnings, in my case especially from iAds. Since I'm only interested in my own debug statements, is there a way to specifically output what I want to see?
I notice there's an option to show either "Debugger Output" or "Target Output." What is the difference between these and can they help with what I'm trying to do?
Another solution would be to block warnings from iAds, autolayout, etc., if that is possible. Is there a way to suppress specific warnings?
What hv88 is saying is that "Debugger output" is the text that comes from the lldb commands you've typed into the console, and "Target Output" is everything that your program writes to stdout. The debugger has no way to tell the difference between "text YOUR code writes to stdout" and "text other libraries write to stdout." It is just one output stream. So that set of choices won't help you with what you want to do.
Note that the console window does have a Find entry, though you won't see it till you type Cmd-F when focused on the console window. So if you mark your output entries with some string that is unique and not to hard to type, you can use the Console Find to navigate to them quickly.
'Debugger output' contains values that we check while debugging i.e. while debugging we check the value of variable. This value can be printed on console by clicking 'i' button on pop-up shown.
'Target output' contains values printed from NSLog, cout, println etc.
'All output' contains values from Debugger and Target.
The console displays program output and lets you enter commands to the debugger. You specify the type of output the console displays with the pop-up menu at the top of the pane:
All Output: Include target and debugger output.
Debugger Output: Include debugger output only.
Target Output: Include target output only. (e.g NSLog, printf)
https://developer.apple.com/library/mac/recipes/xcode_help-debugger/articles/about_debug_area.html

Debugging variables dynamically in xCode?

What do I need to do to have variables display their values in XCode?
I don't have it in Auto pane, and it also does not show when I hover over it. Why is that?
I can go Add Expression and sometimes it will display it correctly, and I can also do NSLog and log it, but this seems really ridiculous in the year of 2013.
I am using XCode 4.6. Am I doing something wrong, or this basic functionality just does not exist?
You can use the local variables section in the content pane to view variable values while debugging:
You can use shift + command + Y to toggle the above pane.
For more information regarding debugging in xCode, check out the following link.
In the console use the command 'po' (stands for print object)
e.g. po [self myVariable]
This will give you more information than this semi-useless variable tree in the content pane.
hints:
1) Make sure your build configuration is set to Debug, or you can't debug local variables.
2) Sometimes you need to debug structs and primitives, in this case use 'p' instead of 'po'
3) you can use dot notation (po self.myVariable), but for some data types this doesn't seem to work. I believe it depends on your xcode version

Bringing objects from code into the Object inspector

I am running Spyder 2.1.9, and I am liking it. I like how much information is provided by the Object inspector, but it only brings info on the various objects if I either type them into my program via the editor or directly into the Object inspector. Is there any way to highlight an object in your code and bring up the information in the Object inspector?
Also as a secondary question. The auto fill pop up when entering is nice (for instance if I am using the csv module and I type csv. into the editor it brings up all of the possible calls for that module), but doesn't work for Tkinter. Any idea as to why this may be?
The answer to your first question is negative, unfortunately. See official bug report on the Spyder group.
You can use CTRL+I on the console to invoke the Inspector from any object, and you can also use it on functions (but not arbitrary objects/variables) from the editor. It's a known inconsistency.
For example, type the following into your Editor window:
import math
x = 3.14159
y = math.sin(x)
Now click on the word math and press CTRL-I. Nothing happens. Click on the word sin and press CTRL-I. The Inspector will show up the documentation for sin().
Now try typing the same three lines into a Python console in Spyder, and repeat. You'll see that pressing CTRL-I after clicking math will work.

Resources