如何在 Xcode 6 调试器中查看 Swift“let”常量的值

2023-11-26

当我在 Xcode 6 中的调试器中停止时,如何查看使用以下命令声明的本地 Swift 常量的值let?

如果我创建一个全新的 Swift 项目在 Xcode 6 中添加以下两行application(_:didFinishLaunchingWithOptions:)在应用程序委托中:

let someConstant = 5
var someVariable = 6

…然后运行应用程序并在这些行之后立即中断,这是我在调试器的变量视图中看到的内容:

screenshot of variables view; someVariable shows 6 and someConstant is listed twice without showing its value

为什么变量显示其值,而常量不显示? (为什么这个常数列出了两次?)

如果,在 LLDB 控制台中,我尝试p, po, or fr v on someConstant (all其中正确显示的值someVariable),我得到以下信息:

screenshot of console; p and po both result in a "use of unresolved identifier" error and fr v displays someConstant as "empty constant data"

我知道我可以使用以下方法打印调试器中的值println在我的源代码中,但我真的不想每次我只是想检查我声明为常量的值时都必须有先见之明。 (即使是跑步expr println(someConstant)在 LLDB 控制台中产生了与以下相同的“无法解析的标识符”错误p and po.)

这应该很容易。我缺少什么?


这是 Xcode 中的一个错误,我可以确认它已在 Xcode 6.1 中修复。 (谢谢,史蒂夫·罗森伯格。)

这就是我现在得到的,正如预期的那样:

screenshot of console; p, po, and fr v now all display the value of someConstant in some way or another

该常量现在也可以在变量视图中正确显示,并且不再列出两次:

screenshot of variables view; someVariable shows 6 and someConstant shows 5

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Xcode 6 调试器中查看 Swift“let”常量的值 的相关文章

随机推荐