'Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained

前端 未结 6 774
谎友^
谎友^ 2020-12-25 11:30

I\'m getting the error above, but unsure how to go about fixing it. This is my code:

.h:

#import 

@protocol ColorLineDelegate &         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 11:31

    I had the same problem when I used old example code which did not feature ARC in my ARC project. It seems that you do not need to put the variable declarations into the interface definition any more. So your code should work like this:

    h:

    #import 
    
    @protocol ColorLineDelegate 
    
    -(void)valueWasChangedToHue:(float)hue;
    
    @end
    
    @interface ColorLine : UIButton {
    
        // Get rid of this guy!
        //id  delegate;
    }
    
    @property (nonatomic, assign) id  delegate;
    
    @end
    

    .m:

    #import "ColorLine.h"
    
    @implementation ColorLine
    
    @synthesize delegate;
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
        }
        return self;
    }
    
    @end
    

提交回复
热议问题