8

I have a few constants files "Constants.h" in my project that I am including in the Prefix.pch file to be available to all the classes in my project. They just contain a bunch of #define statements.

My classes don't recognize these constants (no autocomplete) and Xcode gives me "Undeclared Identifier" errors every time I use them. However when I run the project everything works fine (set to ignore errors).

Is there any way I can get rid of these warnings? #pragma ignore them in the prefix file or something? I've tried many options, including setting "precompile prefix header" to NO in build settings.

Any ideas?

EDIT: I have tried deleting derived data and cleaning / deleting build folder to no avail.

It might be worth noting that I have 3 targets in my project, and another project within this project.

Also, some of the #imports import normal classes. Like a category extension on UIFont and an Analytics class. Could this affect it?

Eliza Wilson
  • 1,031
  • 1
  • 13
  • 38
TTillage
  • 1,886
  • 2
  • 12
  • 10
  • 3
    "Undeclared identifier" is an error, not a warning. You cannot compile and run a program using undeclared identifiers. – Martin R Aug 16 '12 at 16:36
  • Edited to correct that, I meant error. I have it set to ignore errors so the program still compiles and runs fine, xcode just gives me these errors when I'm editing code. – TTillage Aug 16 '12 at 17:08
  • And it doesn't recognize them right away after building, usually only when i'm inside a class that uses those constants does it start seeing the 'errors' – TTillage Aug 16 '12 at 17:09
  • What exactly have you set to "ignore errors"? You cannot compile and run a program containing errors. – Martin R Aug 16 '12 at 18:56
  • it's better to "answer your own question" than to edit the question itself and mark it as "solved", so that it doesn't appear in the "unanswered questions" list. – john.k.doe Aug 16 '12 at 19:11
  • I couldn't answer my own question because it wouldn't let me, because "new users cannot answer their own questions within 4 hours of posting" – TTillage Aug 17 '12 at 21:05

4 Answers4

10

To fix this, I had to change the 'Precompile Prefix Header' flag to NO in my target's Build Settings. By doing this you'll lose any build performance achieved by having a cached compiled header file, but in my case, my Prefix Header is pretty small so I wont see a hit in the time it takes to build.

Peter
  • 2,005
  • 1
  • 20
  • 14
3

Try deleting the project derived data. Xcode sometimes needs to re-index your project to remove "errors" such as this.

Organizer > Projects > Your Project

Click on the "Delete" button to the right of the Derived Data row.

Immediately quit Xcode, and then reopen.

Ian L
  • 5,553
  • 1
  • 22
  • 37
2

I had the PCH file importing .h file with a lot of macros (specifically, I use the MJGAvailability header that warns when I use features that are newer than my deployment target). Replacing:

#import "MJGAvailability.h"

with

#include "MJGAvailability.h"

solved this issue for me.

fishinear
  • 6,101
  • 3
  • 36
  • 84
0

I had a preprocessor macro in one of my targets that I moved from 'preprocessor macros' to 'preprocessor macros not used in precompiled headers' and that solved the problem.

Ben
  • 51,770
  • 36
  • 127
  • 149
TTillage
  • 1,886
  • 2
  • 12
  • 10