How to view value of Swift “let” constant in Xcode 6 debugger

落爺英雄遲暮 提交于 2019-12-18 16:54:34

问题


When I'm stopped in the debugger in Xcode 6, how can I view the value of a local Swift constant declared with let?

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?)

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:

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?


回答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:



来源:https://stackoverflow.com/questions/26189424/how-to-view-value-of-swift-let-constant-in-xcode-6-debugger

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!