当没有后备变量时,在Xcode调试器中查看合成属性的值 [英] Seeing the value of a synthesized property in the Xcode debugger when there is no backing variable

查看:118
本文介绍了当没有后备变量时,在Xcode调试器中查看合成属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在我的iPhone项目中使用合成实例变量。问题是,我在调试器中看不到合成的ivars。当没有使用显式声明的实例变量时,有没有办法在调试器中查看对象的属性?

I just recently began using synthesized instance variables in my iPhone projects. The problem is, I can't see the synthesized ivars in the debugger. Is there any way to view the properties of an object in the debugger when it's not using the explicitly declared instance variables?

我需要澄清第二个问题。我不是在询问如何访问属性或他们做什么;我知道那些东西。在使用基于无法无法直接访问实例变量的印象-modern-runtime>这篇文章。我显然能够做到我以前认为不可能的事情。我想知道发生了什么。

I need to clarify the second question. I'm not asking about how to access properties, or what they do; I know all that stuff. I was under the impression that you could not access instance variables directly when using synthesized ivars based on this post. I've clearly been able to do what I previously thought wasn't possible. I'm wondering what's going on.

我正在使用Xcode 3.2.4 / iPhone模拟器/ LLVM编译器1.5。

I'm using Xcode 3.2.4/iPhone Simulator/LLVM Compiler 1.5.

推荐答案

编辑为第二部分添加答案:

这适用于Xcode 3.1所以我不明白为什么它不适用于更高版本

This works on Xcode 3.1 so I don't see why it won't work on later versions

您可以做的是在调试时从控制台直接向对象发送消息。

What you could do is send messages directly to the object from the console while debugging.

大概你已经在断点处停了下来,而且你正在查看调试视图中的变量。对于对象,这些显示指针。你可能看不到iVar,但你有指向对象的指针,你可以发送消息。例如:

Presumably you've stopped at a breakpoint and you're looking at the variables in the debug view. for objects, these show you the pointers. You may not see the iVar, but you have the pointer to the object and you can send it messages. for example:


  • 您已停止在对象内的某个断点处

  • 变量视图显示 self 的指针地址为(比方说) 0x1031380

  • In控制台类型 po [0x1031380标题] (请注意,没有分号)并输入

  • 您应该看到您想要的内容控制台。

  • You've stopped at some breakpoint within the object
  • The variable view shows the pointer address of self to be (say) 0x1031380.
  • In the console type po [0x1031380 title] (note that there is no semicolon) and enter
  • You should see what you want in the console.

当您使用声明属性时(保留)并随后合成属性,您正在创建保留传递给它们的对象/值的setter。所以在你的情况下你应该重写方法:

When you declare a property with (retain) and subsequently synthesize the property, you're creating setters that retain the object/value passed to them. so in your case above you should rewrite the method as:

- (void)viewDidLoad {
    self.title = @"woah";
}

字符串将作为setter的一部分保留。此外,我更喜欢对具有可变/不可变对的类集群使用(copy) NSString NSSet NSArray 等)。这样,该物业不能在外部进行更改。

And the string will be retained as part of the setter. Also, I prefer to use (copy) for class clusters that have mutable/immutable pairs (NSString, NSSet, NSArray, etc). That way, the property can't be changed externally.

这篇关于当没有后备变量时,在Xcode调试器中查看合成属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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