I am following Core Data Utlity Tutorial to understand the ground work needed in order to make Core Data work. This utility creates a Core Data storage and saves the process id and run date & time every time it runs. It also shows the details of previous runs.
Everything was going fine till managed object class is defined. It is defined as below:
@interface Run : NSManagedObject
{
NSInteger processId;
}
@property (assign) NSInteger processId;
@property (retain) NSDate* date;
@property (retain) NSDate* primitiveDate;
@end
It defines 2 different date properties. Tutorial also defines a method in which primitiveDate is set when a new object is inserted.
- (void) awakeFromInsert {
[super awakeFromInsert];
self.primitiveDate = [NSDate date];
}
I don’t understand why we are setting primitiveDate instead of date property. I don’t even know why primitiveDate is even defined when all we needed was date and processId. I tried to read between the lines (after reading all the lines), but still couldn’t get it. Please can you help? I don’t know what am I missing.
The important line is
in the documentation you quoted. The difference between
and
is that the former issues the Key-Value-Observing (KVO) notifications, but the latter doesn’t. The built-in undo system of Cocoa+CoreData looks for the KVO notification to properly prepare the undo stack. This means that, if you do the former, you can undo that operation from the UI, which you probably do not want.
It’s a subtle difference which becomes important as your program become bigger and more mature.