为什么我在定义委托时遇到错误"无法使用手动引用计数合成文件中的弱属性"?

Che*_*ong 2 delegates class objective-c

我在一个文件中有协议和类头:

@protocol SomethingDelegate
- (void) doSomething;
@end

@interface SomethingClass
@property (nonatomic, weak) id <SomethingDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)

在.m文件中:

@implementation SomethingClass // in here I got error "Cannot synthesize weak property in file using manual reference counting"

@end
Run Code Online (Sandbox Code Playgroud)

如果我把它改成这样:

@implementation SomethingClass 

@synthesize delegate; // in here I got error "Cannot synthesize weak property in file using manual reference counting"

@end
Run Code Online (Sandbox Code Playgroud)

为什么会这样?以及如何解决这个问题?如果我从更改错误消失weakstrong.但这不是代表应该如何宣布,对吧?如何正确宣布弱代表?

San*_*ani 18

您需要设置Weak References in Manual Retain ReleaseYESApple LLVM 8.0 - Language - Objective CBuild Settings你的项目,如screenshot-图所示

在此输入图像描述