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.
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.
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()
.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With