Skip navigation.
 
mltransient attributes of NSManagedObject reflected in isUpdated
FROM : Michael Link
DATE : Tue Apr 29 21:55:31 2008

I noticed that if you have a transient attribute in an NSManagedObject 
and update that attribute then isUpdated will return that the object 
has unsaved changes. I suppose this makes some sense if the attribute 
is actually defined in the entity. On the other hand if the managed 
object has a subclass and a custom instance variable and a setter 
method such as (using GC):

@property(assign) NSImage* iconImage;

- (void)setIconImage:(NSImage*)value
{
   // isUpdated returns 0
   [self willChangeValueForKey:@"iconImage"];
   _iconImage = value;
   [self didChangeValueForKey:@"iconImage"];
   // isUpdated returns 1
}

The attribute isn't in the model and I don't really want Core Data to 
know anything about it because it can't be saved in the store etc...

After this method is used isUpdated will return that the object has 
unsaved changes, even though the attribute isn't part of the model and 
changedValues is empty (since it's quite transient). My guess would be 
that didChangeValueForKey: always sets a flag that marks the object as 
being updated (even though none of the changes can be saved, and funny 
enough when I quit the application is asks me if I want to save the 
unsaved changes).

I'm trying to avoid having the object marked as updated because it 
causes some issues with sorting being quite inaccurate for an 
NSArrayController that uses lazy binding.

Is there anyway to set a custom instance variable in an 
NSManagedObject subclass by still being key-value friendly and not 
marking the object as updated?

--
Michael

Related mailsAuthorDate
No related mails found.