objective-c - 为什么在定义委托(delegate)时出现错误 "Cannot synthesize weak property in file using manual reference counting"?

标签 objective-c class delegates

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

@protocol SomethingDelegate
- (void) doSomething;
@end

@interface SomethingClass
@property (nonatomic, weak) id <SomethingDelegate> delegate;
@end

在 .m 文件上:
@implementation SomethingClass // in here I got error "Cannot synthesize weak property in file using manual reference counting"

@end

如果我把它改成这样:
@implementation SomethingClass 

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

@end

为什么会这样?以及如何解决这个问题?如果我从 weak 更改,错误就会消失至strong .但这不应该是如何声明委托(delegate)的,对吧?如何正确声明弱委托(delegate)?

最佳答案

您需要设置Weak References in Manual Retain ReleaseYES在您的 Apple LLVM 8.0 - Language - Objective CBuild Settings 下您的项目,如下图所示 -

enter image description here

关于objective-c - 为什么在定义委托(delegate)时出现错误 "Cannot synthesize weak property in file using manual reference counting"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41035227/

相关文章:

iOS - 为什么我的 UIAlertView 上的底部项目是粗体?

Swift:UITableViewCell 中的 UITextField 委托(delegate)不起作用

java - 使用泛型时,javac 编译器是否为每种类型创建不同的类?

c# - 将枚举元素作为事件参数传递 C#

c# - 委托(delegate)给实例方法不能有 null 'this'

iphone - info.plist 用途

objective-c - 如何实现 Snow Leopard 停靠式菜单?

ios - 本地通知在错误的时间发送

c# - 内部类访问修饰符不起作用?

c++ - 运算符 << 重载