Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2010, 11:53 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 6
cetcet is on a distinguished road
Default 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:

Code:
@interface SwitchViewController : UIViewController {
	
     FirstViewController *firstViewController;
     SecondViewController *secondViewController;
	
}

@property (retain, nonatomic) FirstViewController *firstViewController;
@property (retain, nonatomic) SecondViewController *secondViewController;
and the beginning of the .m looks like this:

Code:
#import "SwitchViewController.h"

#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation SwitchViewController

@synthesize FirstViewController;
@synthesize SecondViewController;
But when I add a third view, like this:

Code:
@interface SwitchViewController : UIViewController {
	
     FirstViewController *firstViewController;
     SecondViewController *secondViewController;
     ThirdViewController *thirdViewController;
	
}

@property (retain, nonatomic) FirstViewController *firstViewController;
@property (retain, nonatomic) SecondViewController *secondViewController;
@property (retain, nonatomic) ThirdViewController *thirdViewController;
and:

Code:
#import "SwitchViewController.h"

#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"

@implementation SwitchViewController

@synthesize FirstViewController;
@synthesize SecondViewController;
@synthesize ThirdViewController;
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?
cetcet is offline   Reply With Quote
Old 09-14-2010, 12:02 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 10
Thallius is on a distinguished road
Default

sorry wrong idea

Claus
Thallius is offline   Reply With Quote
Old 09-14-2010, 12:41 PM   #3 (permalink)
Fly-by-night Innovator
 
Join Date: Jun 2010
Posts: 364
musicwind95 is on a distinguished road
Default

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!


For more iOS Development, check out my blog—Cups of Cocoa. All visitors welcome, but especially beginners!

Hope I have helped!

Please check out IceFall, a new action game available in the App Store!
musicwind95 is offline   Reply With Quote
Old 09-14-2010, 02:37 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 6
cetcet is on a distinguished road
Default

Quote:
Originally Posted by musicwind95 View Post
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 View Post
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?
cetcet is offline   Reply With Quote
Old 09-14-2010, 04:10 PM   #5 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

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.
JasonR is offline   Reply With Quote
Old 09-14-2010, 04:17 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 6
cetcet is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
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?
cetcet is offline   Reply With Quote
Old 09-14-2010, 04:41 PM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

its called a circular reference.

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.
smithdale87 is offline   Reply With Quote
Old 09-14-2010, 04:50 PM   #8 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

The problem is the your SwitchViewController.h is before your ThirdViewController.h. So when the compiler hits this line:

Code:
     ThirdViewController *thirdViewController;
It doesn't yet know what a ThirdViewController is yet. That's what the error is probably telling you.
JasonR is offline   Reply With Quote
Old 09-14-2010, 05:15 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 6
cetcet is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
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?
cetcet is offline   Reply With Quote
Old 09-14-2010, 06:23 PM   #10 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

No problem at all. In fact, it's often recommended to use the @class in your .h files and the .h inside your .m files.
JasonR is offline   Reply With Quote
Reply

Bookmarks

Tags
expected, specifier-qualifier-list, uiviewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
19 members and 305 guests
2ndSegment, appservice, bignoggins, cayladv57, cgokey, dermotos, djohnson, Domele, EXOPTENDAELAX, guusleijsten, Hamad, heshiming, linkmx, Objective Zero, Rudy, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,654
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cayladv57
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0