Re: Prefix header/objects with mutual references
Re: Prefix header/objects with mutual references
- Subject: Re: Prefix header/objects with mutual references
- From: Shaun Wexler <email@hidden>
- Date: Sun, 21 Nov 2004 18:49:05 -0800
On Nov 21, 2004, at 5:09 PM, david [james] allison wrote:
How, then, do I get ClassA to know about ClassB, if ClassB has to know
about ClassA first?
Use forward declarations of classes (without importing their actual
headers), so you have no header dependencies.
// -------------------------------------------------------
// ClassA.h
#import <Cocoa/Cocoa.h>
@class ClassB;
@interface ClassA : NSObject
{
NSMutableArray *arrayOfClassBObjects;
ClassB *anotherClassBObject;
}
// methods
@end
// -------------------------------------------------------
// ClassB.h
#import <Cocoa/Cocoa.h>
@class ClassA;
@interface ClassB : NSObject
{
ClassA *parentObject;
}
// methods
@end
In your implementation files, you will import the actual headers.
// -------------------------------------------------------
// ClassA.m
#import "ClassA.h"
#import "ClassB.h"
// methods
@end
// -------------------------------------------------------
// ClassB.m
#import "ClassB.h"
#import "ClassA.h"
// methods
@end
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
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