Re: willChangeValueForKey, Ivars and Core Data
Re: willChangeValueForKey, Ivars and Core Data
- Subject: Re: willChangeValueForKey, Ivars and Core Data
- From: Jim Correia <email@hidden>
- Date: Mon, 19 Sep 2005 07:48:13 -0400
On Sep 19, 2005, at 1:14 AM, Scott Ahten wrote:
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.
How would CoreData know whether or not your transient attribute has
any persistent attributes derived from it? (This information cannot
be expressed in the model.)
If CoreData didn't mark the object dirty when a transient attribute
changed, the delayed-update set accessor pattern for non-standard
attribues wouldn't work.
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/
Articles/cdNSAttributes.html>
In other cases, it can be a nuisance that changing a transient
attribute marks the object dirty. In this situation I've reconsidered
my use of transient attributes on a case by case basis to see if that
is really what I needed, or if a plain old iVar would better suit my
needs.
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
That is correct. Automatic key value observing is turned off for
subclasses of NSManagedObject. You need to re-enable it per key for
plain old iVars, or manually invoke will/didChangeValueForKey.
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.
[...]
How do I avoid setting my document as dirty yet notify any objects
observing this value that it has changed?
I don't have a standalone example which currently does this. Have you
set a breakpoint to see who is marking the document dirty?
Jim
_______________________________________________
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