gpt4 book ai didi

objective-c - 'unsafe_unretained 属性 'delegate' 的现有 ivar 'delegate' 必须是 __unsafe_unretained

转载 作者:太空狗 更新时间:2023-10-30 03:09:03 26 4
gpt4 key购买 nike

我遇到了上述错误,但不确定如何修复它。这是我的代码:

.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

错误发生在合成线。不过我找不到问题。

最佳答案

使用这个语法:

@interface SomeClass  : NSObject {
id <SomeClassDelegate> __unsafe_unretained delegate;
}
@property (unsafe_unretained) id <SomeClassDelegate> delegate;

关于objective-c - 'unsafe_unretained 属性 'delegate' 的现有 ivar 'delegate' 必须是 __unsafe_unretained,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8138902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com