@class vs. #import

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

    Three simple rules:

    • Only #import the super class, and adopted protocols, in header files (.h files).
    • #import all classes, and protocols, you send messages to in implementation (.m files).
    • Forward declarations for everything else.

    If you do forward declaration in the implementation files, then you probably do something wrong.

提交回复
热议问题