unsafe_unretained属性'delegate'的'现有ivar'delegate'必须为__unsafe_unretained [英] 'Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained

查看:79
本文介绍了unsafe_unretained属性'delegate'的'现有ivar'delegate'必须为__unsafe_unretained的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到上述错误,但是不确定如何解决.这是我的代码:

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

.h:

#import <UIKit/UIKit.h>

@protocol ColorLineDelegate <NSObject>

-(void)valueWasChangedToHue:(float)hue;

@end

@interface ColorLine : UIButton {

    id <ColorLineDelegate> delegate;

}

@property (nonatomic, assign) id <ColorLineDelegate> 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

在合成行中发生错误.我还是找不到问题.

The error occurs in the synthesize line. I can't find a problem though.

推荐答案

看起来您的项目可能正在使用ARC,则应以这种方式声明属性:

Looks like your project might be using ARC then properties should be declared this way:

#import <UIKit/UIKit.h>

@protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
@end

@interface ColorLine : UIButton 
@property (nonatomic, weak) id <ColorLineDelegate> delegate;
@end

这篇关于unsafe_unretained属性'delegate'的'现有ivar'delegate'必须为__unsafe_unretained的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆