I have this problem with po
in the console where trying to output a function works in itself, but outputting a variable or constant doesn't.
As you can see here, although you'd think the var/let holds the content of bar.boy()
, Swift somehow can't find it...
Fixed after setting:
Optimization Level = None[-Onone]
under Swift Compiler - Code GenerationNote that setting
Optimization Level
under Apple LLVM 8.0 - Code Generation has no effectSo it turns out there was probably a bug in the past that when you were adding a Swift file it would add/ask a Bridging header, but it wouldn't add that line to your project
which means you'd stay in this state
resulting in
error: <EXPR>:1:1: error: use of unresolved identifier
!I could only find that out because I moved around files in my project and when I added ObjC files to the project, it asked me about a Bridging header (although I had one already!) and luckily added that
SWIFT_OPTIMIZATION_LEVEL
. One could consider this is a bug to consider the default value isfastest
, but then again I guess this was only a bug in the past and got fixed now.Still, I fixed now it might be a bug the other way around, if it add
none
in the release build. I can't test this right now because for testing this I only had aDebug
build. I'll leave that as an exercise :) for Apple's Engineers.If your project is using Swift, there are two separate "Optimization Level" settings in the project/target configuration. Its not only "SWIFT_OPTIMIZATION_LEVEL". Check this link: https://stackoverflow.com/a/32984193/2060180
I'll leave it here in case it's useful to someone.
I bet that bug is due to the fact that
foo
has been optimized out during compilation and it's symbol does not exist anymore in the compiled code (even if it shouldn't have in debug and it's still an LLDB bug)Probably if you add some usage of
foo
in the next lines (even a println) its symbol will hopefully be kept in the IR and you'll be able topo foo
(I agree that that's still a bug but at least if it works you'll have a workaround and some sense of explanation)
I set Swift Complier to "-O"
and set it back to "-Onone".
Then it works.
I encountered a similar issue but I already had the correct configuration, all optimisations set to
None
. However I still didn't get any values.After some further digging I found out that the issue originated from Xcode being unable to the resolve the types:
That led me to this question: xcode 8 Debugger 'Could not resolve type' where the issue is described and the bridging header seems to cause issues.
With my project not having any bridging headers I studied the build settings once more and found this setting
This was initally set to
YES
. After changing the it toNO
symbols are working again.SWIFT_INSTALL_OBJC_HEADER = NO