1

I am using a Constants.h file to declare a lot of strings for resources like URLs and the like. This has always worked fine in the past, and in fact continues to work when I compile and run.

However the issue navigator shows errors (the red bangs) despite labeling them as "semantic issues" (which sounds more like a warning) and the code editor windows show them as well for lines like this:

[app openBrowserWithUrl:[NSURL URLWithString: kRequestInformationURL]];

The line in Constants.h looks like this:

static NSString * const kRequestInformationURL = @"http://www.myserver.com"; // uses SSL!

It's throwing up warnings/errors for all of my declarations in Constants.h. But it still compiles and runs fine! I have no clue what's going on here, but it's very annoying because my project now shows that I have lots of warnings/errors.

I should also add that this happens in the latest version (4.5.1) of Xcode on one of my Macs and not the other, opening the exact same project file.

Another thing I should note: you usually only see these error/warnings when you click on the file to edit it after compiling.

UPDATE EDITED: I thought that I got these to go away by adhering to more strict constants declarations, as explained in this post: https://stackoverflow.com/a/539039/326398 however all the warnings (which, as I said before, are marked with error icons in Xcode) came right back. So mystery is still very much intact.

Community
  • 1
  • 1
avance
  • 1,993
  • 2
  • 21
  • 23
  • **Xcode is not a compiler.** Also, if it compiles and runs, then it was not an error, only a warning. –  Oct 19 '12 at 21:11
  • and yes, I have done "clean" and "clean build folder" numerous times.... – avance Oct 19 '12 at 21:12
  • I know Xcode isn't a compiler, but it is showing compiler errors in the issue navigator. Thanks for your help, though. – avance Oct 19 '12 at 21:13
  • Oh, I see. Edited the question anyways for clarity. –  Oct 19 '12 at 21:13
  • Xcode marks warnings with a yellow triangle, and errors with a red circle. I am seeing the latter, not the former, so they are being marked as errors, not warnings. However the compiler (I have it set to LLVM) doesn't seem to have a problem with them so it makes the build anyway. – avance Oct 19 '12 at 21:15
  • Despite the fact they are some weird hybrid of error and warning, they shouldn't be either. It is perfectly valid code that threw no warnings whatsoever before! – avance Oct 19 '12 at 21:19
  • 1
    this might indeed be either a compiler bug or you misunderstanding const correctness. If it's neither, I'm out of ideas. :( –  Oct 19 '12 at 21:30
  • If it wasn't acting different on two different machines, I'd be less confused! I probably don't understand the best practice for constant declarations in a precompiled header (.pch) file, but I'll read up on it. – avance Oct 22 '12 at 00:08
  • Nope, implementing constants the kosher way ended up making no difference in the end. – avance Oct 23 '12 at 21:49

1 Answers1

1

Thats happening when you use "false" variables, your NSString is declared as *"const", you cannot do that because const is actually an own Declaration for something in Xcode, simply change NSStrings variable name.

Maurice
  • 1,466
  • 1
  • 13
  • 33
  • Thanks for the insight, but it doesn't explain why Xcode never had a problem with it before and then all of the sudden it does? And on my other Mac, also using latest Xcode, I can open the project and not get *any* of these warnings? – avance Oct 21 '12 at 22:53
  • So try compiling the project on your other Mac... I can just tell you what I know. – Maurice Oct 22 '12 at 15:00
  • Just change your NSString name... that will fix it, dunno where your problem is because you asked for the reason of that warning - i gave it to you... seems not to be okay for you...? – Maurice Oct 22 '12 at 18:54