Re: Core Data : Correct way to force reading property from sql store?
Re: Core Data : Correct way to force reading property from sql store?
- Subject: Re: Core Data : Correct way to force reading property from sql store?
- From: Keary Suska <email@hidden>
- Date: Sun, 15 Jan 2012 10:53:54 -0700
On Jan 14, 2012, at 2:35 PM, Jerry Krinock wrote:
> I want my app to access the new value of an object's property stored in an sqlite store, after this value has been modified on disk by another process.
>
> A few weeks ago, I did this, and I thought it was working:
>
> [[obj managedObjectContext] refreshObject:self
> mergeChanges:YES] ;
> id foo = [obj foo] ;
I don't know that I have anything useful to say but the fact that you are trying to fault an object inside the object itself seems like a code smell. Or do you mean to instead do:
[[obj managedObjectContext] refreshObject: obj
mergeChanges:YES] ;
Do you experience the same behavior if you refresh the object from a point outside the object, also making sure that it is not retained by anything outside the MOC?
> However, upon retesting today I found that foo was the old value, and after puzzling over the documentation of -[NSManagedObject refreshObject:mergeChanges:], and some experimentation, I fixed it by doing this instead:
>
> [[obj managedObjectContext] processPendingChanges] ; // just in case
> NSTimeInterval oldStaleness = [[obj managedObjectContext] stalenessInterval] ;
> [[obj managedObjectContext] setStalenessInterval:0.0] ;
> [[obj managedObjectContext] refreshObject:self
> mergeChanges:NO] ;
> id foo = [obj foo] ;
> [[obj managedObjectContext] setStalenessInterval:oldStaleness] ;
>
> By the way, oldStaleness is the default value of -1.0.
>
> Is there a better way?
>
> It seems like "gimme the latest value of object.foo from the disk" shouldn't be so hard. If all you read is the first line of that documentation [1], you think that it is easy!
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden