@class vs. #import

后端 未结 16 1294
渐次进展
渐次进展 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:17

    Look at the Objective-C Programming Language documentation on ADC

    Under the section on Defining a Class | Class Interface it describes why this is done:

    The @class directive minimizes the amount of code seen by the compiler and linker, and is therefore the simplest way to give a forward declaration of a class name. Being simple, it avoids potential problems that may come with importing files that import still other files. For example, if one class declares a statically typed instance variable of another class, and their two interface files import each other, neither class may compile correctly.

    I hope this helps.

提交回复
热议问题