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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to