__unsafe_unretained for a delegate won't build

后端 未结 2 1449
鱼传尺愫
鱼传尺愫 2021-02-01 23:58

I have this code (snippet) from a .h file:

#import 
#import \"ILView.h\"

/**
 * Controls the orientation of the picker
 */
typedef enum {
          


        
相关标签:
2条回答
  • 2021-02-02 00:31

    As the error message is telling you, the ivar:

    @interface ILHuePickerView : ILView {
        id<ILHuePickerViewDelegate> delegate;    // <-- This is the ivar
    

    needs to be declared __unsafe_unretained:

    __unsafe_unretained id<ILHuePickerViewDelegate> delegate;
    

    not the property:

    @property (assign, nonatomic) IBOutlet id<ILHuePickerViewDelegate> delegate;
    

    because the ARC ownership qualifiers don't apply to properties; they only apply to variables.

    Since the @synthesize directive creates the ivar for you (with the correct ARC qualifier), however, you can just skip its declaration:

    @interface ILHuePickerView : ILView 
    
    /**
     * Delegate
     */
    @property (assign, nonatomic) IBOutlet id<ILHuePickerViewDelegate> delegate;
    
    // etc.
    

    Which is, in fact, now the recommended procedure; see Defining Classes in TOCPL.

    0 讨论(0)
  • 2021-02-02 00:52

    I've used ILColorPicker in the past, and it is definitely not ARC ready. Set -fno-objC-arc in the compiler flag settings for the ILColorPicker classes.

    0 讨论(0)
提交回复
热议问题