-[NSManagedObjectContext hasChanges] returns 1, yet no visible changes? (was Re: refreshObject:mergeChanges: vs. stale transient properties)
-[NSManagedObjectContext hasChanges] returns 1, yet no visible changes? (was Re: refreshObject:mergeChanges: vs. stale transient properties)
- Subject: -[NSManagedObjectContext hasChanges] returns 1, yet no visible changes? (was Re: refreshObject:mergeChanges: vs. stale transient properties)
- From: Jim Correia <email@hidden>
- Date: Wed, 10 Aug 2005 12:34:44 -0400
On Aug 9, 2005, at 8:09 PM, mmalcolm crawford wrote:
The cached value is used on the next accessor invocation (I've
stepped through it.)
Any further advice or hints?
What I ended up doing was, since I couldn't clear the transient
attribute in didTurnIntoFault, was to simply set a flag that the
attribute is stale and should be recomputed.
... this is as good an implementation as you're likely to get.
So that is what I did. [code below for reference]
I do notice that after refreshing the managed object context
(refreshObject:mergeChanges: passing YES) that the target context is
marked dirty - that is hasChanges returns true.
If l look at the context, the insertedObjects are empty,
deletedObjects are empty, and updatedObjects contains the Person and
the Resume object. If I ask those objects for their changedValues,
both return empty dictionaries, yet hasChanges returns true. (Person
has a to-one relationship to resume, resume has an inverse. I don't
yet have a standalone example that shows the problem.)
Does anyone know why this is?
Under what conditions will hasChanges return true?
If I comment out the line which caches the unarchived string in a
transient property, it appears that the problem goes away.
Should setting a transient property mark the context dirty? I am
using the on-demand get accessor pattern
http://developer.apple.com/documentation/Cocoa/Conceptual/
CoreData/Articles/cdNSAttributes.html
Thanks,
Jim
- (void)didTurnIntoFault
{
_attributedStringValueIsStale = YES;
[super didTurnIntoFault];
}
- (NSAttributedString *)attributedString
{
NSAttributedString *attributedString = nil;
if (! _attributedStringValueIsStale)
{
[self willAccessValueForKey:@"attributedString"];
attributedString = [self
primitiveValueForKey:@"attributedString"];
[self didAccessValueForKey:@"attributedString"];
}
if (attributedString == nil)
{
NSData *data = [self data];
if (data != nil)
attributedString = [NSKeyedUnarchiver
unarchiveObjectWithData: data];
[self setPrimitiveValue: attributedString forKey:
@"attributedString"];
}
_attributedStringValueIsStale = NO;
return attributedString;
}
_______________________________________________
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