On Dec 21, 2007, at 11:17 PM, Mike Kobb wrote: I spent a couple of hours in XCode this evening debugging a "bug" that turned out not to be a bug in my code at all. But, thanks to some XCode oddness, I wasted a huge amount of time. I'd appreciate some thoughts on what I can do differently in the future. Here were the two problems I had:
1) I had an NSString with the path to which I was to download a file. It's going into the user temporary directory, so the path is relatively lengthy. When I looked at the string in XCode, it appeared to be truncated a few characters before the end. I spent a long time trying to figure out why the string was being truncated before I finally figured out that the string was actually fine, but XCode was truncating the display without any indication. My string was 110 characters long, but XCode was displaying only the first 100 characters. No matter which window I looked at this string in, it appeared to be truncated, even in the tool tip. Shouldn't XCode have given me some indication that it was abbreviating the display? I finally figured out that it was okay when I looked at the memory directly.
One way I do it is to right-click on the object in the Debugger window and choose "Print Description to Console". This always prints the entire string contents.
I can understand how this would be confusing. Please file a bug if you'd like to indicate to Apple that it's an important issue to you.
2) After sorting out that problem, I hit another problem. My code makes the following call (where archivePath is an NSString):
NSString *filePath = [archivePath stringByDeletingPathExtension];
This function is documented in the Apple developer docs as follows: - (NSString *)stringByDeletingPathExtension
Yet, when I tried to view the contents of this item, it seemed to be either empty or invalid. I tried to "View Value As..." an NSString *, but that still displayed no text. The initial class that shows up when I open the View Value As window is "NSPathStore2 *". Is there some way I could have actually viewed this result as an NSString, which is what the documentation says that the function returns? Also, given the fact that these path utilities are pretty fundamental, shouldn't XCode be able to display "Summary" information for whatever class this really is? Maybe it is an invalid object? If so, the debugger will have trouble showing it to you, because it doesn't have the correct information it needs to do the display.
Also, the type might be less useful than you would think, because the underlying class hierarchy of Foundation classes isn't always so simple. This isn't a problem with Xcode, this is an issue that Foundation finds it useful to return subclasses of types, instead of simple NSString objects, for internal reasons.
For example, for a straight NSString created from a string constant, if I go to the Console window in Xcode, and type:
po [myString class]
the type returned is "NSCFString" ("po" stands for "print object"). This is an internal implementation type.
You can find out if it's a subclass of NSString by doing the following (note the required typecasts for "print"):
print (int)[myString isKindOfClass:(Class)[NSString class]]
but it's probably best just to send it the messages that you want results from, such as this:
po [myString description]
Hope that helps a bit.
-- Andrew |