Re: [newbie] Cyclic #import
Re: [newbie] Cyclic #import
- Subject: Re: [newbie] Cyclic #import
- From: King Chung Huang <email@hidden>
- Date: Tue, 07 Dec 2004 21:13:30 -0700
In your header (.h) files, you can just prototype the class, then import the actual header in your implementation (.m) files as needed.
For example, in MyController.h, you would write:
#import <Cocoa/Cocoa.h>
@class MyNetworker;
@interface MyController : NSObject {
IBOutlet MyNetworker *networker;
}
King Chung Huang
Learning Commons
University of Calgary
On Dec 7, 2004, at 8:57 PM, Malte wrote:
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 _______________________________________________
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
_______________________________________________
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