在调试时查看Xcode中的对象/属性状态 [英] View object/property state in Xcode while debugging

查看:1208
本文介绍了在调试时查看Xcode中的对象/属性状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是Xcode的新手,在iOS项目上工作,而我正在进行最根本的调试。具体来说,我需要能够查看对象的状态,因为我逐步浏览代码(这不是疯狂的),但是我不知道在Xcode中如何做到这一点。

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.

这里我试图查看 store.storeHours 数组,没有运气。实际上左边的视图告诉我数组中有0个对象,当我尝试扩展它时不会显示任何东西,但是当我 po store.storeHours 控制台显示7个对象,尽管无用地被描绘为内存地址。

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!

更新:所以事情变得更加恶化!当我将变量显示切换到Auto而不是Auto时, self.store.storeHours 变得完全可导航!我想知道是否有一个错误访问正确的StoreHours实例或某事,因为它清楚地识别阵列中的7个对象,当我现在看!更不用说对象是可以扩展的,因为我最初希望。

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.

推荐答案

实例实际上是提供信息本身。您需要实现 描述 方法,它继承自 NSObject ,为您的自定义类按顺序因为他们能够打印自己作为除内存地址之外的东西(这是 NSObject 的实现)。

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];
}

该方法只需要返回一个 NSString 包含您认为在检查对象时看到的任何信息。

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

这也是当您使用%@ 格式说明符在 NSLog()

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

这篇关于在调试时查看Xcode中的对象/属性状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆