Reputation: 1227
Would like to group all header files in my project in one class ,so that i neednt import it in every class rather one header will be enough,
if possible is there any overheads ??
Upvotes: 0
Views: 88
Reputation: 104698
This is exactly how:
#import <SomeFramework/SomeFramework.h>
operates.
There will be overhead -- there may be more files to read, and there will be more to parse. Whether that is an acceptable amount of overhead is for you to decide.
ObjC programs can be developed to have very very little physical dependence, and with #import
, you save a ton of redundant reopening of headers (vs headers which may be included multiple times). Therefore, the impact will be quite small, if done correctly.
The bigger problem may be figuring out how to avoid exposing other frameworks to your client.
#import <SomeFramework0/SomeFramework0.h>
#import <SomeFramework1/SomeFramework1.h>
#import <SomeFramework2/SomeFramework2.h>
#import <SomeFramework3/SomeFramework3.h>
#import <SomeFramework4/SomeFramework4.h>
#import <SomeFramework5/SomeFramework5.h>
200 lines from your headers vs 200 headers from the lib's dependencies…
I often do what you are proposing to insulate clients from changes in dependencies. They don't want to #include
every class individually and maintain that as things move around over time -- they just want to use the library/package without hassle.
Upvotes: 1
Reputation: 137382
It is possible, create another header that includes all other includes and include only it:
common.h:
#include <somefile.h>
#include <anotherFile.h>
#include <andAnotherOne.h>
in each other file, you only need to:
#include "common.h"
Though I would consider it a bad idea, as you expose more than you need to each class, and you violates the separation of modules in your program. Also, the preprocessor will need to work more, and maybe the compiler as well.
Upvotes: 1