Re: "Recursive" #imports
Re: "Recursive" #imports
- Subject: Re: "Recursive" #imports
- From: Chris Hanson <email@hidden>
- Date: Thu, 14 Jun 2007 12:19:02 -0700
On Jun 14, 2007, at 11:22 AM, Alain Schartz wrote:
I'm having problems with the #import statement :
I have a ClassA, #import-ing ClassB.h ; and ClassB #import-ing
ClassA.h. If I try to compile this, I get parse errors from the
compiler, indicating that something is wrong in my header files. I
was aware that the #include-statement could generate this kind of
problem, but I thought that #import would save me from exactly this
kind of thing?
Unfortunately ClassA needs access to ClassB's methods and vice-
versa, disqualifying the use of the @class-directive... So I'm kind
of stuck here!
ClassA's implementation needs to know about ClassB's methods.
However, that doesn't mean you need to #import ClassB in ClassA's
header file.
Generally, in a header file, you should only #import the header files
that declare:
* Your superclass, or the framework it's from.
* Any protocols your class implements.
* Any enums or structs that are used directly (rather than via a
pointer) in your class declaration.
Everything else you can use forward declarations -- "@class ClassB;"
or @"@protocol Foo;" or "struct XYZ;" -- to declare in your header.
Then #import the headers for these in your implementation (.m) file
itself.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden