• 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: Is there a bug in #include operation? (I meant #import)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a bug in #include operation? (I meant #import)


  • Subject: Re: Is there a bug in #include operation? (I meant #import)
  • From: Denis Stanton <email@hidden>
  • Date: Tue, 2 Mar 2004 10:35:17 +1300

Hi Sherm

thanks for the fast response

In reading your helpful response I realized with horror (well with embarrassment at least) that I had miss-stated the problem. I wrote a question about #include when I meant to write #import. I have no #includes in my code, they are all really #imports.

You have recommended the solution that I eventually came up with - put the imports of other class headers into the .m files so that importing a .h file does not bring along all its friends.

Thank you for your help. I'm moving forwards again.

Denis

On Tuesday, March 2, 2004, at 10:15 AM, Sherm Pendley wrote:

On Mar 1, 2004, at 3:33 PM, Denis Stanton wrote:

Is there a problem in Xcode 1.1's handling of #include where classes are mutually dependent ?

There are many ways to work around circular dependencies like you're describing.

The best way is to avoid them to begin with. Most .h files don't actually need to import other .h files - for argument and return types, you don't need the whole class definition, so declaring the classes with @class is generally good enough. You can import the whole header file in the .m file, where knowing the exact methods an object responds to is actually important.

For protocols, put them in .h files by themselves, and declare arguments and return types that use them as id<ProtocolName> - that is, an object that conforms to the given protocol.

Minimizing the cross-includes and circular dependencies will also speed up your build times, by minimizing the number of .m files that have to be rebuilt each time a header is changed.

A class does need to include its superclass' header, though.

For that, the easiest thing to do is simply use #import instead of #include - it's an Objective-C improvement over #include that essentially says "include this if it hasn't been included already."

Alternatively, you can do what C programmers have been doing since nearly day zero, and wrapping your headers in guardian #ifdef directives. For example, in foo.h, you'd do something like this:

#ifndef __FOO_H__
#define __FOO_H__

... interesting stuff goes here...

#endif

sherm--


Denis Stanton
email@hidden
Home: +64 9 533 0391
mobile: +64 21 1433622
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Is there a bug in #include operation? (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Is there a bug in #include operation?
  • Next by Date: Re: Databasing and Cocoa
  • Previous by thread: Re: Is there a bug in #include operation?
  • Next by thread: Re: Is there a bug in #include operation?
  • Index(es):
    • Date
    • Thread