FROM : Jonathan del Strother
DATE : Sun Apr 20 17:32:21 2008
On Sun, Apr 20, 2008 at 4:25 PM, Don Arnel <<email_removed>> wrote:
> I have two different class objects that need to know about each other (see
> below). But if I include the header from one class inside the header of the
> other class the compiler complains. Is this even possible?
>
> ClassOne.h:
> ----------------
>
> #import "ClassTwo.h"
>
> @interface ClassOne : NSObject {
>
> ClassTwo *objectTwo;
> }
>
> @end
> ----------------
>
>
> ClassTwo.h:
> ----------------
>
> #import "ClassOne.h"
>
> @interface ClassTwo : NSObject {
>
> ClassOne *objectOne;
> }
>
> @end
Pre-declare the classes with '@class' - eg
@class ClassTwo;
@interface ClassOne : NSObject {
ClassTwo *objectTwo;
}
@end
You'll still need to import 'ClassTwo.h' in your implementation file.
It's a good idea to do that instead of importing any of your own
headers within header files. Things can get a bit contorted
otherwise.
DATE : Sun Apr 20 17:32:21 2008
On Sun, Apr 20, 2008 at 4:25 PM, Don Arnel <<email_removed>> wrote:
> I have two different class objects that need to know about each other (see
> below). But if I include the header from one class inside the header of the
> other class the compiler complains. Is this even possible?
>
> ClassOne.h:
> ----------------
>
> #import "ClassTwo.h"
>
> @interface ClassOne : NSObject {
>
> ClassTwo *objectTwo;
> }
>
> @end
> ----------------
>
>
> ClassTwo.h:
> ----------------
>
> #import "ClassOne.h"
>
> @interface ClassTwo : NSObject {
>
> ClassOne *objectOne;
> }
>
> @end
Pre-declare the classes with '@class' - eg
@class ClassTwo;
@interface ClassOne : NSObject {
ClassTwo *objectTwo;
}
@end
You'll still need to import 'ClassTwo.h' in your implementation file.
It's a good idea to do that instead of importing any of your own
headers within header files. Things can get a bit contorted
otherwise.
| Related mails | Author | Date |
|---|---|---|
| Don Arnel | Apr 20, 17:25 | |
| Jean-Daniel Dupas | Apr 20, 17:32 | |
| Jonathan del Strot… | Apr 20, 17:32 |






Cocoa mail archive

