Adding a new view controller causes 'Expected specifier-qualifier-list' error
I've got a controller that manages multiple views called SwitchViewController. It works fine, provided I only have two views. The .h file looks like this:
All of the new lines in the .h throw this error during compile:
Code:
Expected specifier-qualifier-list before 'ThirdViewController'
I can comment out the new lines, and it compiles fine. If I put 'em back, the error returns. The ThirdViewController.h and ThirdViewController.m are identical to the SecondViewController.h and SecondViewController.m, and the associated .xib is basically empty.
I'm at a loss as to why two views works while the third does not. Any suggestions?
Check to make sure ThirdViewController.h doesn't import any of the other headers...the error sometimes occurs with cyclical imports. Also check for missing semicolons. It's one of those cryptic compiler errors...
Also, try using LLVM instead of GCC (Project > Edit Project Settings > Build > Compiler Version)
__________________
If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!
Check to make sure ThirdViewController.h doesn't import any of the other headers...the error sometimes occurs with cyclical imports. Also check for missing semicolons. It's one of those cryptic compiler errors...
Thanks for the quick reply! I checked for cyclical imports: nada. ThirdViewController is a virgin sublcass of UIViewController; haven't so much as typed a comment into it.
Quote:
Originally Posted by musicwind95
Also, try using LLVM instead of GCC (Project > Edit Project Settings > Build > Compiler Version)
No luck - same error as before.
This happened to me on another project too. I tried deleting the ThirdViewController .h, .m, and .xib files and recreating them, but the same thing happens. Nothing I do seems to help; I even tried changing the compilation order by drag-dropping the entries in the Targets-->Compile Sources branch. It just won't compile.
Everything about ThirdViewController is identical to SecondViewController except for the name. I just don't get it. Any other ideas?
What does the beginning of your .h file look like? It looks like the ThirdViewController is not being defined, by either including the ThirdViewController.h or using a @class declaration.
What does the beginning of your .h file look like? It looks like the ThirdViewController is not being defined, by either including the ThirdViewController.h or using a @class declaration.
Thanks for the reply. The includes are all there. Recapping my original post, this line is indeed in my SwitchViewController.m:
Code:
#import "ThirdViewController.h"
(see the bolded text at the beginning of this thread.)
Any reason I should be using @class for ThirdViewController when #import works just fine for FirstViewController and SecondViewController?
I think a good rule of thumb is to always use @class in your .h files instead of importing the headers. In your .m file, import the required .h files. This will always help you avoid circular references.
I think a good rule of thumb is to always use @class in your .h files instead of importing the headers. In your .m file, import the required .h files. This will always help you avoid circular references.
Adding this line to the .h did the trick:
Code:
@class ThirdViewController;
Turns out that I already had @class lines for FirstViewController and SecondViewController; I've been staring at this for so long, I just didn't see them any more. It works now.
I still need the #include lines, though - without them, it won't compile. Any problem referencing controllers with both @class and #import lines?