2014-10-04 30 views
6

當我在Xcode 6中的調試器中停止時,如何查看用let聲明的本地Swift常量的值?如何在Xcode 6調試器中查看Swift「let」常量的值

如果我在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控制檯,我嘗試ppo,或fr vsomeConstant所有這些的正確顯示的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打印在調試器的價值,但我真的不想要有先見之明做的,每次我只是希望檢查我宣佈爲一個騙局的價值STANT。 (即使在LLDB控制檯中運行expr println(someConstant)也產生了與ppo相同的「未解決的標識符」錯誤。)

這應該很簡單。我錯過了什麼?

+1

看到這裏的第二個答案:http://stackoverflow.com/questions/24309005/po-swift-string-unresolved-identifier視; Y,這是一個公認的錯誤。 – 2014-10-04 04:19:48

+1

做檢查 - SWIFT_OPTIMIZATION_LEVEL http://stackoverflow.com/a/28518621/1294448 – 2015-08-13 08:17:08

回答

2

這是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

+3

仍然發生在我xcode 6.1.1 – user1366265 2015-04-01 13:17:36

+0

我有同樣的問題,但即使有變量...沒有優化和發佈模式!無法理解發生了什麼! – 2016-11-12 09:05:09

相關問題