Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View object/property state in Xcode while debugging

So I'm new to Xcode, working on an iOS project and I'm having a heck of a time with the most fundamental debugging. Specifically I need to be able to view the state of objects as I step through the code (that's not crazy is it?), but I can't for the life of me figure out how to do this in Xcode.

Whenever I try, it seems the furthest I get is a memory address that can't be expanded to show its objective contents. Nor can I figure out any way to even manually dereference the pointer in the debug console to view the state of that object.

Here I am trying to view the contents of the store.storeHours array, with no luck whatsoever. In fact the view on the left tells me there are 0 objects in the array, and won't show anything when I try to expand it, but when I po store.storeHours the console shows 7 objects, albeit uselessly portrayed as memory addresses.

enter image description here

Please tell me I'm not crazy and I'm just missing something!

Update: So things get even weirder! When I switch the variable display to "Local" instead of "Auto" suddenly, self.store.storeHours becomes fully navigable! I'm wondering if perhaps there was a glitch accessing the correct "storeHours" instance or something because it's clearly identifying 7 objects in the array when I view it now! Not to mention the objects are expandable as I was originally hoping.

enter image description here

like image 986
devios1 Avatar asked Feb 27 '13 00:02

devios1


2 Answers

The instances are actually providing that information themselves. You need to implement the description method, which is inherited from NSObject, for your custom classes in order for them to be able to print themselves as something other than a memory address (which is what NSObject's implementation does).

I've no idea what properties your Hours class has, but this is as simple as something like:

- (NSString *)description
{
    return [NSString stringWithFormat:@"Open: %i Close: %i", self.openTime, self.closeTime];
}

The method just needs to return an NSString containing whatever information you think is important to see when inspecting the object.

This is also how classes represent themselves when you use the %@ format specifier in NSLog().

like image 86
jscs Avatar answered Sep 19 '22 19:09

jscs


In your example, store.storeHours is an empty NSArray. So, naturally, you can't look inside it.

For more clarity in the debugger, try adding a method (inherited from NSObject)

 - (NSString*) description

to your objects like Hours that tells you more about their contents. See also debugDescription.

like image 34
Mark Bernstein Avatar answered Sep 22 '22 19:09

Mark Bernstein