• 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: "Recursive" #imports
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Recursive" #imports


  • Subject: Re: "Recursive" #imports
  • From: Alain Schartz <email@hidden>
  • Date: Thu, 14 Jun 2007 21:56:19 +0200

After implementing the proposed changes everything works fine ; all I had to do was declare my classes in the header files (using @class) and really #import the header files in the implementation files.

Thanks for the quick replies,
Alain

On Jun 14, 2007, at 9:44 PM, Gregory Weston wrote:

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?

What import does is guard against circular and redundant inclusions. It's a convenience against having


#ifndef _MY_HEADER_
#define _MY_HEADER_
// all the stuff you really want
#endif

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!

Generally people use the @class declaration to _defer_ the #import, not obviate it. Use @class where you need the names and import the headers where you actually need the methods. If that's giving you errors it probably suggests there's actually something wrong/odd about your headers and we can't really suggest what that is without seeing them.


G
_______________________________________________

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

_______________________________________________

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


References: 
 >Re: "Recursive" #imports (From: Gregory Weston <email@hidden>)

  • Prev by Date: Re: -[NSPredicate evaluateWithObject:] and NSArray
  • Next by Date: Re: Core Data Beginner Question
  • Previous by thread: Re: "Recursive" #imports
  • Next by thread: NSColorPicker cusomt minimum view size
  • Index(es):
    • Date
    • Thread