0

Ok this is probably a silly question but why can I do something like this:

objectA.h

#import <objectB>
#import <objectC>

objectA.m

#import <ObjectA.h>

And in ObjectA.m have access to ObjectB and OBjectC definition ? It's silly to have to import everything you use in each implementation file. Am i missing something obvious ?

Abizern
  • 146,289
  • 39
  • 203
  • 257
CodeFlakes
  • 3,671
  • 3
  • 25
  • 28

2 Answers2

3

Rather than importing headers in your .h file you could just use the @class declaration for objects you need to declare in your header file, and then in your .m file #import the header files you need.

I'm not sure if this is what you are asking, though.

This has been discussed in more detail in this SO Question

Community
  • 1
  • 1
Abizern
  • 146,289
  • 39
  • 203
  • 257
2

You can do this, and it can occasionally make sense -- provided that the definitions are coupled in such a way that they genuinely belong together.

What you shouldn't do is introduce bogus compilation dependencies just to save a few keystrokes in some implementation file.

walkytalky
  • 9,453
  • 2
  • 36
  • 44