Can't check when NSDate is NULL
ios, nsdate
Solution
`<null>` is the description of `NSNull`, not that of `nil` (or `Nil` or `NULL` which are the same). Try
if (![oldTime isEqual:[NSNull null]])
instead.
Problem
I create an entity named "NoteEntity" in CoreData and generate NSManageObject subclass ``` @interface NoteEntity : NSManagedObject @property (nonatomic, retain) NSDate * time; @end ``` Then I addObserver to check time change when select object: ``` [self addObserver:self forKeyPath:@"noteEntity.time" options:NSKeyValueObservingOptionOld context:KNoteEntityTime]; ``` Observer Code: ``` - (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]; } } ``` I need to check if noteEntity.time change from NULL but the if (oldTime != NULL) or if(oldTime) not WORK, here is the log ``` CHANGE:From <null> - (null) CHANGE:From <null> - 2013-07-29 10:15:58 +0000 ``` Please help me find out what I'm doing wrong. Thanks!