@class vs. #import

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

    This is an example scenario, where we need @class.

    Consider if you wish to create a protocol within header file, which has a parameter with data type of the same class, then you can use @class. Please do remember that you can also declare protocols separately, this is just an example.

    // DroneSearchField.h
    
    #import 
    @class DroneSearchField;
    @protocol DroneSearchFieldDelegate
    @optional
    - (void)DroneTextFieldButtonClicked:(DroneSearchField *)textField;
    @end
    @interface DroneSearchField : UITextField
    @end
    

提交回复
热议问题