`po` gives `error: <EXPR>:1:1: error: use of unresolved identifier`

StuFF mc picture StuFF mc · Feb 13, 2015 · Viewed 18k times · Source

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.

first result is for <code>po bar.boy()</code>, second says <code>unresolved</code>

As you can see here, although you'd think the var/let holds the content of bar.boy(), Swift somehow can't find it...

Answer

StuFF mc picture StuFF mc · Feb 14, 2015

So 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

SWIFT_OPTIMIZATION_LEVEL = "-Onone";

which means you'd stay in this state

SWIFT_OPTIMIZATION_LEVEL fastest

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 is fastest, 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 a Debug build. I'll leave that as an exercise :) for Apple's Engineers.