Objective-C: Importing headers in .h or .m?

后端 未结 4 1389
我在风中等你
我在风中等你 2021-02-02 09:15

I\'m new to objective-c and would like to know the best practice for importing some external headers that I use in my class.

Should I be storing the #import \"classB.h\"

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 09:55

    To the compiler, it really doesn't matter. You could just throw forward declarations in your .h and then wait to #import until your .m file. See this post on SO for more info on this.

    From a clean-code prospective, some may argue that putting the imports in your implementation file keeps the details closer to where they are needed (see that link above as well; the people there reference this idea).

提交回复
热议问题