Swift variables not available

Whenever I have to debug something written in Swift, I'm always running into unavailable variables. If you try to print one in the debug window it just says "<variable not available>".


I've checked all the obvious stuff. I'm not debugging a release build, and I don't have any optimizations turned on.


I've never run into this problem with Objective-C code.


I've read old posts from years ago that say "Swift debugging in Xcode ***** right now" but surely whatever problems or bugs there may have been in the past have been fixed by now.


What's going on here?

Post not yet marked as solved Up vote post of flarosa Down vote post of flarosa
2k views

Replies

What version of Xcode are you testing with?

Is this problem limited to your project? Or does it affect all projects on your machine?

For example, if you create a new project from the macOS > Command Line Tool template, set

main.swift
to look like that shown below, and then set a breakpoint on line 4, do you see values for
a
and
b
.
func main() {
    let a = 1
    let b = 2
    print(a + b)
}
main()

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Yes, I see the values of a and b in that example.

Cool. The trick now is to try to isolate what’s causing the problem in your specific project. One way to do that is to take a snippet of code that has a problem in your main app and move it to your test project, stubbing out whatever is necessary to get it to build. That should give you some hint as to whether the problem is with your code and with your project.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"