willChangeValueForKey, Ivars and Core Data
willChangeValueForKey, Ivars and Core Data
- Subject: willChangeValueForKey, Ivars and Core Data
- From: Scott Ahten <email@hidden>
- Date: Mon, 19 Sep 2005 01:14:28 -0400
I have a subclass of NSManagedObject with a transient attribute that
is calculated from other attributes of the entity.
A NSTimer is used to calculate and update this value every second,
which is displayed in a NSTableView column in my UI using KVO.
However, when this attribute is set, a dark dot is displayed in the
close button and the document is flagged as "dirty". Since this
attribute is set to transient in my CoreData model, not used to set
other persistent properties, nor are any persistent attributes
"dependent" on this attribute, I'm not sure why the document thinks
it's dirty and needs to be saved.
In an attempt to resolve this issue, I've created a ivar for the
attribute in my NSMangedObject subclass and manage it's storage
myself. After creating my own accessor methods, setting this value no
longer marks my document as dirty, but the table column is not
notified of the change. Wrapping the assignment in my accessor with
willChangeValueForKey: and didChangeValueForKey: calls updates the
table, but marks the document as dirty even though this value is no
longer and attribute of my CoreData model and I'm managing my own
storage.
- (void)setTimeInHMS:(NSString *)value
{
if (HMSString != value) {
[self willChangeValueForKey:@"timeInHMS"];
[HMSString autorelease];
HMSString = [value retain];
[self didChangeValueForKey:@"timeInHMS"];
}
How do I avoid setting my document as dirty yet notify any objects
observing this value that it has changed?
Thanks,
- Scott
- - -
:: email@hidden
:: http://www.pixelfreak.net
- - -
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden