【发布时间】:2010-12-02 16:15:39
【问题描述】:
大家好,我有一个协议,它定义了许多 ObjC-2.0 属性,如下所示:
@protocol Repeatable <NSCoding>
@required
@property (nonatomic, retain) Date *startDate;
@property (nonatomic, retain) Date *endDate;
@end
我有另一个实现协议的类:
@interface AbstractRepeatable : NSObject <Repeatable>
最后,在 AbstractRepeatable 中,我正在实现协议定义的方法:
- (BOOL)isEqualToRepeatable:(Repeatable *)r {
if (r.startDate != startDate) // Compiler error here
return NO;
return YES;
}
出于示例的原因,已排除了一些零碎的内容,但是在编译时,我在上面提到的行中收到了熟悉的“对成员 'startDate' 的请求,而不是结构或联合”。 AbstractRepeatable 显然包含Repeatable 标头,否则协议将不可见,所以我不知道我缺少哪个部分。
【问题讨论】:
-
这个答案可能会为您解决一些问题:stackoverflow.com/questions/844678/…
-
我正在合成 AbstractRepeatable 中的属性,我无法弄清楚为什么无法识别该道具。
标签: iphone objective-c xcode macos properties