[newbie] Cyclic #import
[newbie] Cyclic #import
- Subject: [newbie] Cyclic #import
- From: Malte <email@hidden>
- Date: Wed, 8 Dec 2004 04:57:44 +0100
Hey folks,
yet another question from the noobster.
I will explain my situation quicky:
i have created my GUI in IB.
In IB i have subclassed NSObject twice, once as "MyController" once as "MyNetworker"
The Controller is (conforming to MVC) supposed to handle all the user-input coming from the "view/GUI" whereas the "MyNetworker" is supposed to setup a TCP connection and handle all that jazz. The idea is, that i don't want to clutter my Controller with "low-level network" stuff. He is just to juggle the data from the Networker back to the View and vice versa.
So the two classes (MyController & MyNetworker) each have one outlet where they're supposed to hook up with one another. I have instantiated those two subclasses and in IB connected the blue instance-cubes (i love those icons :)) witheachother, hooking them up to eachother's outlet like so:
MyController ------> MyNetworker
MyNetworker ------> MyController
In IB i have created the files for those classes and the relevant lines are being pasted here:
**************************************************************
/* MyController.h */
#import <Cocoa/Cocoa.h>
#import "MyNetworker.h"
@interface MyController : NSObject
{
IBOutlet MyNetworker * networker;
}
****************************************************
/* MyNetworker.h */
#import <Cocoa/Cocoa.h>
#import "MyController.h"
@interface MyNetworker : NSObject
{
IBOutlet MyController * controller;
}
***************************************************************
Problem is, that this never builds. The compilation aborts complaining about something right before the beginning of the implementation files (vaguely hinting at the #imported interfaces :).
I then //commented out the #import and IBOutlet in one of the two and the compilation went through without complaining.
So i figured that the cyclic #imports are not to the compiler's liking.
Then i thought to myself "Hey....isn't it true that the interface-file actually doesn't care about the header of the outlets? I left the #import statement commented out but brought the IBOutlet back to life.
The compiler didn't like this and errored out (a little question on the side: why is that? i can have all kinds of outlets where i don't have to include the headers i.e. 'IBOutlet NSTextField * inputTest' doesn't require me to #import the <AppKit/NSTextField.h> file in the header but outletting a custom class i need to?)
So apparently i have to leave the #import statement intact. Which puts me back to the cyclic #import situation.
I scampered across various google results regarding this problem but all i could find was that in C you could help this by using "forward declaration" using some "class" syntax which seems to be very different from the @interface style in Obj-C.
Bottom line:
How do i go about this thing? How do i have two classes outletting to eachother without being caught in the cyclic #import pinch?
Thanks a lot for reading all this,
-malte
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden