Malloc
Malloc

Reputation: 16256

Error: Expected specifier-qualifier-list before XXX

it did it so many times and i didn't had any problems with it, but this time i still getting the error above, my relevant code is this:

#import "PiecesChoisies.h"

@interface SelectionMobilier : UIViewController {
IBOutlet PiecesChoisies *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies 
}
@end

Thanx in advance for any suggestions :)

EDIT : I try this :

#import "PiecesChoisies.h"

    @interface SelectionMobilier : UIViewController {
    IBOutlet NSString *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies 
    }
    @end

Now i got this stack:

enter image description here

Upvotes: 0

Views: 1108

Answers (3)

Jano
Jano

Reputation: 63667

PiecesChoisies is not recognized as a type. This may happen because it has cyclical dependencies.

The following code example illustrates the problem. Classes A and B create a circular dependency trying to import each other.

#import "B.h"               // <-- A imports B
@interface A : NSObject
@end

#import "A.h"
@implementation A
@end


#import "A.h"              // <-- and B imports A
@interface B : NSObject
@end

#import "B.h"
@implementation B
@end

Because the classes are never created, the compiler treats them as unknown tokens, so the error shows as Expected specifier-qualifier-list before XXX. In other words "I expected something meaningful before XXX".

To remove the circular dependency:

  1. And add a forward class declaration (@class) on the interface file.
  2. Move the #import from the interface to the implementation file.

The class declaration tells the compiler "don't worry, I'll define this later", so the header becomes safe to import because the conflicting definition is now out of sight on the implementation file.

Here is the result for the previous example:

@class B;             // <---- #import "B.h" replaced with @class B
@interface A : NSObject
@end

#import "A.h"
#import "B.h"         // <---- #import "B.h" added
@implementation A
@end

And do the same with class B:

@class A;             // <---- #import "A.h" replaced with @class A
@interface B : NSObject
@end

#import "B.h"
#import "A.h"         // <---- #import "A.h" added
@implementation B
@end

Upvotes: 2

jrturton
jrturton

Reputation: 119242

If this is in a header file, use

@class PiecesChoisies;

Instead of the import statement. Import the .h file in your .m file.

Upvotes: 0

Max MacLeod
Max MacLeod

Reputation: 26652

The problem will be located in PiecesChoisies.h. Change:

 IBOutlet PiecesChoisies *piecesChoisies;

to

 IBOutlet NSString *piecesChoisies;

that will confirm that the problem is located in the .h file.

Upvotes: 0

Related Questions