Re: [CoreData] Background Insertion
Re: [CoreData] Background Insertion
- Subject: Re: [CoreData] Background Insertion
- From: "Marcus S. Zarra" <email@hidden>
- Date: Tue, 5 Jun 2007 13:15:38 -0600
This is very odd. I did get it to work by changing your dataSaved:
method to:
- (void)dataSaved:(NSSet*)list
{
if ( usesPrepareContent )
[listController prepareContent];
else
{
NSEnumerator* enumerator = [list objectEnumerator];
NSManagedObjectID* objectid;
while ( (objectid = [enumerator nextObject]) != nil )
{
NSManagedObject* object = [managedObjectContext
objectWithID:objectid];
[managedObjectContext refreshObject:object mergeChanges:NO];
}
[listController prepareContent]; //MSZ Added
}
[list release];
}
As to why this is necessary, I am stumped. It should be picking it
up automatically. This solves it but I am not sure if you want to do
something like this. Although having your delegate broadcast a "data
updated" notification might solve the issue.
When I do background processing, I close all of the windows that
display the data and bring up a progress dialog which is modal. So I
am probably not seeing this behavior because the controller reload
when the windows get presented. Now I will have to go back into my
code and see if I can duplicate this behavior and join you in a radar
filing...
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
On Jun 5, 2007, at 12: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];
}
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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