Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MickeyT

macrumors member
Original poster
Apr 26, 2010
92
0
Newcastle, United Kingdom
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
 
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.
 
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.
 
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.