Re: [CoreData] Background Insertion
Re: [CoreData] Background Insertion
- Subject: Re: [CoreData] Background Insertion
- From: Andrew Kimpton <email@hidden>
- Date: Tue, 5 Jun 2007 15:15:15 -0400
On Jun 5, 2007, at 2:35 PM, Dave Hayden wrote:
On Jun 5, 2007, at 9:08 AM, Marcus S. Zarra wrote:
The order should be as follows:
1. Insert objects on background thread
2. Hold a reference to these objects
3. Save objects on background thread
4. Build an array list of objectIDs on background thread
5. Send array list of objectIDs to main thread
6. Update on main thread.
If you retrieve the objectIDs from the managed objects after they
have been saved then they should have their permanent unique ids.
No luck here. This is the bit from the worker thread:
NSSet* insertedObjects = [context insertedObjects];
if ( ![context save:&error] )
...
NSSet* insertedIDs = [[insertedObjects valueForKey:@"objectID"]
retain];
[self performSelectorOnMainThread:@selector(dataSaved:)
withObject:insertedIDs waitUntilDone:NO];
and here's what the dataSaved: method does:
NSEnumerator* enumerator = [list objectEnumerator];
NSManagedObjectID* objectid;
while ( (objectid = [enumerator nextObject]) != nil )
{
NSManagedObject* object = [managedObjectContext
objectWithID:objectid];
[managedObjectContext refreshObject:object mergeChanges:NO];
}
I'm seeing the same thing here (in my own project). It's not
specifically related to threading either, in my case I've dispensed
with the extra thread and just have two managed object contexts. I've
also tried the code both with and without a save message to the
managed object context - in all cases any object created with
insertNewObjectForEntityForName returns nil from
registeredObjectForID called against the other managed object context.
Andrew 8-)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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