#import errors and @class warnings
#import errors and @class warnings
- Subject: #import errors and @class warnings
- From: Andre Doucette <email@hidden>
- Date: Thu, 30 Apr 2009 00:55:30 -0600
Hi everyone!
I have noticed a problem in a few projects and don't understand why. I
have found a work around, but it seems both unnecessary and a pain due
to warnings.
For one example, I have two classes, AppController and
NetworkController.
For the AppController class:
---------------------------------------------------------
#import <Foundation/Foundation.h>
#import "NetworkController.h"
@interface AppController : NSObject {
NetworkController *networkController;
}
@implementation AppController
- (void)awakeFromNib {
networkController = [[NetworkController alloc]
initWithAppController:self];
}
@end
And for the NetworkController class:
---------------------------------------------------------
#import <Foundation/Foundation.h>
#import "AppController.h"
@interface NetworkController : NSObject {
AppController *appController;
}
- (id)initWithAppController:(AppController *)inAppController;
@end
@implementation NetworkController
- (id)initWithAppController:(AppController *)inAppController {
self = [super init];
appController = inAppController;
return self;
}
@end
I want the two controllers to "know" about each other. The
AppController object is created in the NIB file, and in it's
awakeFromNib method, I create the NetworkController object, passing in
a reference to itself.
When trying to compile this, I get a series of errors. In my
AppController.m file, I get "error: syntax error before AppController"
and "warning: '@end' must appear in an @implementation context". In my
NetworkController.m, I get "error: syntax error before
'NetworkController'".
It seems that it doesn't like the double #import, but I thought the
whole idea behind #import was that it ensured one-time includes. If I
take either #import "NetworkController.h" or #import "AppController.h"
and change them to forward declarations (that is, @class
NetworkController; or @class AppController;), this works, but then I
get a sprinkling of errors everywhere saying that methods may not be
implemented.
Any thoughts?
Thanks!
Andre
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden