@class vs. #import

后端 未结 16 1048
渐次进展
渐次进展 2020-11-21 22:42

It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header t

16条回答
  •  一生所求
    2020-11-21 23:30

    Think of @class as telling the compiler "trust me, this exists".

    Think of #import as copy-paste.

    You want to minimize the number of imports you have for a number of reasons. Without any research, the first thing that comes to mind is it reduces compile time.

    Notice that when you inherit from a class, you can't simply use a forward declaration. You need to import the file, so that the class you're declaring knows how it's defined.

提交回复
热议问题