我需要在setter方法中做一些額外的東西。但我這樣做的時候所以得到一個無限循環:用弧和動態屬性覆蓋setter
我有一個核心的數據對象
@interface Transaction : NSManagedObject
@property (nonatomic, retain) NSDate * date;
@end
@implementation Transaction
@dynamic date;
-(void)setDate:(NSDate *)date
{
self.date = date;
//additional stuff omitted
}
所以,在這種情況下,我得到一個無限循環。好了,所以我在網上搜索,並以下列方式修改我的代碼,併爲每一個版本,我得到編譯器錯誤
版本1:
@interface Transaction : NSManagedObject
@property (nonatomic, retain) NSDate * date;
@end
@implementation Transaction
@dynamic date;
-(void)setDate:(NSDate *)date
{
self->date = date; //Error: Property 'date' found on object 'Transaction *'; did you mean to access it with the "." operator?
//additional stuff omitted
}
版本2:
@interface Transaction : NSManagedObject
@property (nonatomic, retain) NSDate * date;
@end
@implementation Transaction
@dynamic date = _date; //Error: Expected ';' after @dynamic
-(void)setDate:(NSDate *)date
{
_date = date;
//additional stuff omitted
}
現在,我我在問自己該怎麼做?
它打破志願... – AlexeyVMP 2013-07-30 05:43:15
呼叫willChangeValueForKey之前和之後didChangeValueForKey保持KVO的底部看到。 – brodney 2014-01-28 14:54:11