Skip navigation.
 
mlSyntax error when declaring an IBOutlet
FROM : Mark Teagarden
DATE : Thu Mar 06 19:16:46 2008

Hi,

My app has three objects - world, mapview, and game, and they need to know
about each other in various combinations: mapview needs an outlet to world
and game, and game needs an outlet to world.  I've ctrl-clicked them all
together appropriately in IB, and now I'm trying to declare the IBOutlets in
code.  So in mapview.h:

#import <Cocoa/Cocoa.h>
#import "World.h"
#import "Game.h"

@interface WMapView : NSView {
    IBOutlet Game * game;
    IBOutlet World * world;
    int view_x, view_y, window;

}

This worked fine and complied correctly.  But the following code (identical,
as far as I can tell) in game.h:

#import <Cocoa/Cocoa.h>
#import "World.h"

@interface Game : NSObject {
    IBOutlet World * world;
}

Throws up: 'syntax error before World' in the IBOutlet statement.  I was
able to get around this by replacing

#import "World.h"

with

@class World

in game.h.

I have another class, Display, that gives me the same error as the one in
game.h - I've omitted it here for clarity.  Basically, the mapview.h #import
/ IBOutlet is the only one that worked correctly.

My questions are:
1.  Why does identical code work in one file and not in the others?
2.  Why should @class work when #import doesn't?  Hillegass flat out says
that the two are interchangeable.

Thanks,
Mark

Related mailsAuthorDate
mlSyntax error when declaring an IBOutlet Mark Teagarden Mar 6, 19:16
mlRe: Syntax error when declaring an IBOutlet David Mar 6, 19:44
mlRe: Syntax error when declaring an IBOutlet Paul Goracke Mar 6, 20:19
mlRe: Syntax error when declaring an IBOutlet Mark Teagarden Mar 6, 21:00
mlRe: Syntax error when declaring an IBOutlet Paul Goracke Mar 6, 21:31