#import or #include header file - file not found

Discussion in 'iOS Programming' started by MickeyT, Jul 1, 2012.

  1. MickeyT macrumors member

    Joined:
    Apr 26, 2010
    Location:
    Newcastle, United Kingdom
    #1
    I have written two classes and would like to be able to create instances of one within the other. When I add the following to the header file, I get an error which says the file can't be found:

    Code:
    #include Card.h
    What am I doing wrong? I have tried this with #import as well as #include, I've moved the header files to the Frameworks folder (which seems to be where the UIKit and Foundation stuff is which are imported successfully as part of the pre-populated code) and Xcode insists it can't find the files.

    At the moment, the header file of the Card class is sitting in the Project Navigator within the main containing project folder, which is where the AppDelegate and a single ViewController are situated.

    As an aside - what is the difference between #import and #include?

    Thanks
     
  2. cMacSW macrumors regular

    Joined:
    Mar 20, 2006
    #2
    Try changing this to:

    Code:
    #include "Card.h"
    Also make sure if this file is not in the project directory you
    add its location to the include path.
     
  3. MickeyT thread starter macrumors member

    Joined:
    Apr 26, 2010
    Location:
    Newcastle, United Kingdom
    #3
    Really sorry - my first post was incorrect. I've been putting the following in the header file:

    Code:
    #include <Card.h>
    I had thought the convention was to use <> in the header file and "" in the implementation file. The <> in the header file has always created the file not found problem.

    I'll try quote marks in the header file and see if that works.

    Thanks.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    That's not the convention. The convention is <> means "don't search in user directories", and "" means "search in user directories". It's plain ordinary C. If you're unsure what that means, you should consult a C reference. Here's a brief summary:
    http://en.wikipedia.org/wiki/C_preprocessor#Including_files

    For a long time now, compilers have supported the option to have <> search user directories, because sometimes it's desirable to replace a system header. This option would be set per-project, by the developer; it's not a given.

    Also, the "" form doesn't necessarily mean "search a single user directory", because large projects are often organized across many directories.

    Objective-C also has the convention that <FrameworkName/headerFile.h> refers to a framework name, regardless of what the actual directory name is. Since frameworks may contain other frameworks and libraries, this convention eliminates the need to know details of a framework's internal organization, since those details can change over time.
     
  5. MickeyT thread starter macrumors member

    Joined:
    Apr 26, 2010
    Location:
    Newcastle, United Kingdom
    #5
    Thank you both - using quote marks has worked and I get the distinction between <> and "".
     

Share This Page