Objective C Delegate declaration

前端 未结 3 823
日久生厌
日久生厌 2021-02-07 08:58

Can someone tell me the difference between

@property (nonatomic, weak) id delegate;

@property (nonatomic, weak) id   delegate;

@property          


        
3条回答
  •  日久生厌
    2021-02-07 09:28

    In the first example:

    @property (nonatomic, weak) id delegate;
    

    you create a property of type id which is 'any' type in objective c with name - delegate.

    The second example:

    @property (nonatomic, weak) id < protocol_name > delegate;
    

    you create a property of type id which needs to conform to protocol_name protocol with name - delegate.

    The last example:

    @property (nonatomic, weak) UIViewController * < protocol_name > delegate;
    

    you create a property of type UIViewController (pointer to UIViewController) which needs to conform to protocol_name protocol with name - delegate.

提交回复
热议问题