Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

xcode6

lldb

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:

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

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:

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

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?

like image 258
George WS Avatar asked Oct 04 '14 03:10

George WS


1 Answers

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:

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

The constant is now displayed correctly in the variables view as well, and is no longer listed twice:

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

like image 93
George WS Avatar answered Oct 21 '22 05:10

George WS