• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Prefix header/objects with mutual references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: tile-based game sample code?
  • Next by Date: Tracking behavior of cells in NSMatrix
  • Previous by thread: Re: tile-based game sample code?
  • Next by thread: Tracking behavior of cells in NSMatrix
  • Index(es):
    • Date
    • Thread