Importing header in objective c

后端 未结 5 1762
情歌与酒
情歌与酒 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:13

    So what is the reason behind this convention?

    You should favor forward declarations (@class MONClass;) where possible because the compiler needs to know a typename is an objc class before it is used, and because an #import can drag in a ton of other headers (e.g. entire frameworks/libraries), seriously expanding and complicating your dependencies and increasing your build times.

    Which is efficient way?

    Forward declarations. Your builds, rebuilds, and indexing will be much faster if you do this correctly.

提交回复
热议问题