Re: [CoreData] Background Insertion
Re: [CoreData] Background Insertion
- Subject: Re: [CoreData] Background Insertion
- From: "Marcus S. Zarra" <email@hidden>
- Date: Mon, 18 Jun 2007 01:03:30 -0600
According to information I received last week, the correct answer for
this problem on Tiger is to loop over the inserted objects, retrieve
them on the main thread and then insert them into the
NSArrayController with addObject:
Not the greatest solution but it will work for now.
Marcus
On 6/5/07, Dave Hayden <email@hidden> wrote:
On Jun 5, 2007, at 2:55 PM, Marcus S. Zarra wrote:
> I wonder if it would be possible to see what notification is being
> sent? If it is a true notification, then you could perhaps
> simulate it yourself....
>
> Might be worth exploring just to see if it can be cleaned up a bit.
It sends a NSManagedObjectContextDidSaveNotification when you save,
but it turns out that the array controller uses a separate private
notification to do the "automatically prepares content": If you catch
the "_NSObjectsChangedInManagingContextPrivateNotification"
notification, pass it to the other thread and rebroadcast it with the
other thread's managed object context as the notification object, it
does update the UI. Not that that's any solution, but it shows a bit
of what's going on under the hood. Now if we could find the
legitimate way to do that..
Another thing that works and may be a bit more kosher: instead of
telling the controller to prepareContent after a save, you can insert
the the objects from the main thread's managed object context
straight into the array controller, avoiding a fetch:
- (void)dataSaved:(NSSet*)list
{
NSEnumerator* enumerator = [list objectEnumerator];
NSManagedObjectID* objectid;
while ( (objectid = [enumerator nextObject]) != nil )
[listController addObject:[managedObjectContext
objectWithID:objectid]];
[listController rearrangeObjects];
}
It seems like this would create a duplicate object in the context,
but I don't get any complaints when the main thread context is saved
on quit and I don't see everything doubled when I open the app next
time.
-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