我創建一個實體,名爲 「NoteEntity」 在CoreData併產生NSManageObject子無法檢查時的NSDate是NULL
@interface NoteEntity : NSManagedObject
@property (nonatomic, retain) NSDate * time;
@end
然後我的addObserver檢查時間的變化時,選擇對象:
[self addObserver:self forKeyPath:@"noteEntity.time" options:NSKeyValueObservingOptionOld context:KNoteEntityTime];
觀察員代碼:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == KNoteEntityTime) {
NSDate *oldTime = (NSDate *)[change objectForKey:NSKeyValueChangeOldKey] ;
if (oldTime != NULL) {
NSLog(@"CHANGE:From %@ - %@",oldTime,self.noteEntity.time);
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
我需要檢查noteEntity.time是否從NULL更改爲if(ol DTIME!= NULL)或者(古來)無法正常工作,這裏是日誌
CHANGE:From <null> - (null)
CHANGE:From <null> - 2013-07-29 10:15:58 +0000
請幫我找出我做錯了。謝謝!
@ isaach1000不,這些都是一樣的。問題是''不是'nil'或'Nil'或'NULL'的描述,而不是'NSNull'的描述。嘗試'if(![oldTime isEqual:[NSNull null]])'而不是。 –
2013-07-29 11:25:55
太棒了!非常感謝@ H2CO3請將其作爲回答 –
不客氣,完成。用對象的描述值得玩一下,這樣你就可以習慣使用NSLog(@「%@」)來打印/記錄什麼了。此外,請務必注意尖括號與正常括號之間的細微細節。 – 2013-07-29 11:31:44