A matter of style ? or substance ?

Discussion in 'Mac Programming' started by mdeh, Oct 17, 2009.

  1. macrumors 6502

    Joined:
    Jan 3, 2009
    #1
    Hi All,
    Up to now, I have always imported classes into the header file, but noticed that in Apple's Sketch program, the programmer imports them into the implementation file.
    Also, found this on StackOverflow.

    Is this a matter of substance or style ? :) Or, is this Holy-War territory?

    Thanks in advance.
     
  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Yes, you will run into problems if you try to #import everything in your .h files, not for everything but it will happen. And some of these errors can be cryptic and hard to figure out exactly what the problem is. I use @class for everything I can in the interface file.
     
  3. Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    i've always wondered about this also, especially since i am under the impression that any import of a header file to the implimentation file will also import the header file's imports.

    Code:
    [B]MyClass.h[/B]
    #import <Foundation/Foundation.h>
    #import <Whatever/Whatever.h>
    #import "ThisClass.h"
    
    @interface MyClass : NSObject
    @end
    
    -=-=-=-=-
    
    [B]MyClass.m[/B]
    #import "MyClass.h"
    
    @implementation MyClass
    @end
    
    so in the code above, since the implimentation file has imported MyClass.h, doesn't it also take <Whatever/Whatever.h> and "ThisClass.h" with it, since it's apart of the header file?

    if so, what potential problems are there if an import occurs in a header rather than the implementation or vice-versa?
     
  4. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    There are a few issues. The primary one is circular imports. a.h imports b.h, b.h imports c.h, and c.h imports a.h. That's safe if you forward-declare with @class, @protocol, etc..., but won't compile properly if you import.

    Secondarily, it can speed up compiles.
     
  5. thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #5

    Thanks to all who answered. I will start following the advice suggested here.
    Thanks.
     

Share This Page