Re: [CoreData] Background Insertion
Re: [CoreData] Background Insertion
- Subject: Re: [CoreData] Background Insertion
- From: Dave Hayden <email@hidden>
- Date: Tue, 5 Jun 2007 11:35:45 -0700
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];
}
Nothing changes in the UI. Calling objectRegisteredForID: instead
returns nil. Changing the mergeChanges: flag doesn't have any effect.
Neither does toggling the array controller's "automatically prepares
content" flag.
Here's a demo project:
http://www.panic.com/~dave/CoreDataTest.zip
-D
_______________________________________________
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