开发者

How to import headers recusively in Objective-C

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开发者_如何学Go to ObjectB and OBjectC definition ? It's silly to have to import everything you use in each implementation file. Am i missing something obvious ?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜