如何查看Swift的"let"值Xcode 6调试器中的常量 [英] How to view value of Swift "let" constant in Xcode 6 debugger
问题描述
当我在Xcode 6中的调试器中停止时,如何查看用let
声明的本地Swift常量的值?
When I'm stopped in the debugger in Xcode 6, how can I view the value of a local Swift constant declared with let
?
如果我在Xcode 6中创建一个全新的Swift项目,并将以下两行添加到应用程序委托中的application(_:didFinishLaunchingWithOptions:)
:
If I create a brand new Swift project in Xcode 6 and add the following two lines to application(_:didFinishLaunchingWithOptions:)
in the app delegate:
let someConstant = 5
var someVariable = 6
…然后运行应用程序,并在以下几行之后立即中断,这是我在调试器的变量视图中看到的内容:
…then run the app and break immediately after these lines, this is what I see in the variables view of the debugger:
为什么变量不显示其值,而常量却不显示? (为什么常数被列出两次?)
Why does the variable display its value, while the constant does not? (And why is the constant listed twice?)
如果在LLDB控制台中尝试在someConstant
上使用p
,po
或fr v
(全部正确显示someVariable
的值),我得到以下信息:
If, in the LLDB console, I try p
, po
, or fr v
on someConstant
(all of which correctly display the value of someVariable
), I get the following:
我知道我可以在源代码中使用println
在调试器中打印值,但是我真的不想每次都只想检查一个值时就具有远见卓识.我已声明为常量. (即使在LLDB控制台中运行expr println(someConstant)
也会产生与p
和po
相同的无法解析的标识符"错误.)
I'm aware that I can print the value in the debugger by using println
in my source code, but I'd really rather not have to have the foresight to do that every time I simply want to inspect a value I've declared as a constant. (Even running expr println(someConstant)
in the LLDB console produced the same "unresolved identifier" error as p
and po
.)
这应该很容易.我想念什么?
This should be easy. What am I missing?
推荐答案
这是Xcode中的一个错误,我可以确认该错误已在Xcode 6.1中修复. (谢谢史蒂夫·罗森伯格.)
This was a bug in Xcode which I can confirm was fixed in Xcode 6.1. (Thanks, Steve Rosenberg.)
这是我现在所得到的,正如预期的那样:
This is what I get now, as expected:
该常量现在也可以正确显示在变量视图中,并且不再列出两次:
The constant is now displayed correctly in the variables view as well, and is no longer listed twice:
这篇关于如何查看Swift的"let"值Xcode 6调试器中的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!