27

我正在使用 ARC(不,这不是 NDA)。我在我的界面中声明我的 ivar

id itemDelegate;

然后我声明属性:

@property (nonatomic, weak) id<mySecretDelegateYouAreNotSupposedToSeeOnSO> itemDelegate;(因为 ARC 而用弱而不是分配)

在我的实现文件中,我只是合成它:@synthesize itemDelegate;

但是,我收到错误:

"Existing ivar 'ItemDelegate' for _weak property 'itemDelegate' must be _weak".

有谁知道怎么了?谢谢你的帮助。

ARC - 自动引用计数

4

3 回答 3

46

尝试类似以下(示例来自:http: //vinceyuan.blogspot.com/2011/06/wwdc2011-session-323-introducing.html):

@interface SomeObject : NSObject {
   __weak id <SomeObjectDelegate> delegate;
}
@property (weak) id <SomeObjectDelegate> delegate;
@end

请注意 ivar 是如何声明的。

于 2011-08-11T07:43:05.877 回答
9

使用 ARC 和 iPhone Simulator 5.0,以下似乎工作得很好(没有警告等......):

一些对象.h

@class SomeObject;
@protocol SomeObjectDelegate <NSObject>
- (void)someObjectDidFinishDoingSomethingUseful:(SomeObject *)object;
@end


@interface SomeObject : NSObject {
   __unsafe_unretained id <SomeObjectDelegate> _delegate;
}
@property (nonatomic, assign) id <SomeObjectDelegate> delegate;
@end

一些对象.m

#import "SomeObject.h"

@implementation SomeObject
@synthesize delegate = _delegate;
@end
于 2011-08-11T08:42:55.497 回答
1

存在一个问题,即使您按照 Apple 的要求从 Mac App Store 更新 XCode(4.2+),它也会在您的计算机上保留旧版本的 XCode。因此,如果您将 XCode 固定到您的启动板并启动它,您将收到所有这些错误,如下所述。您必须找到较新版本的 XCode,例如使用 Spotlight 功能,运行它,然后作为它的首要任务之一,它删除旧版本的 XCode。然后你就不会再有这样的错误报告了。

于 2012-05-15T19:42:29.560 回答