tags:

views:

77

answers:

1

I have an idea on how to do this, but I want to make sure I do it right....

I have five data classes. When I use one I typically use all of them (but not always).

Each class has a separate header file. I am getting sick of linking in each header file separately.

What is the best way resolve this issue?

+7  A: 

Create a new header file called "DataFiles.h". Inside that, have your five #import statements. Then whenever you need the file classes, just #import "DataFiles.h".

Beware of circular dependencies.

(This is how Cocoa, Foundation, UIKit, CoreData, etc all behave. Notice that you just #import <Cocoa/Cocoa.h>, which imports everything else. Open up Cocoa.h and take a look)

Dave DeLong
Shouldn't need to worry about circular dependencies when using #import instead of #include. It is basically the solution to that exact problem.
Ed Marty
#import solves the problem of declaring the same symbol twice, but it will not solve circular dependencies. (A.h imports B.h, and B.h imports A.h). That's why we have forward declarations using the `@class` directive.
Dave DeLong
No, you still need to worry about circular dependencies. If A.h imports B.h and B.h imports A.h, it doesn't work right.
Chuck
@Chuck - great minds think alike. =)
Dave DeLong