Importing header in objective c

后端 未结 5 1758
情歌与酒
情歌与酒 2020-12-31 18:46

In Objective-c when we using object of one class into another class by convention we should forward declare the class in .h file, i.e. @class classname;. And sh

5条回答
  •  梦谈多话
    2020-12-31 19:12

    #import is a pre-processor directive that operates on the file before the compiler sees it. Whenever you get confused, conceptually think of it as like a copy-and-paste: when you see #import foo, the means the contents of file foo are inserted at that point. (It's a bit more clever than that, as it also guards against duplicate includes).

    So you #import Foo.h in Bar.h if there are declarations in Bar.h that reference Foo.h. If there is nothing in Bar.h that uses Foo, but there is Bar.m, then the import goes in Bar.m. Keep the declarations only where they're need.

提交回复
热议问题