• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [CoreData] Background Insertion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: [CoreData] Background Insertion
      • From: "Marcus S. Zarra" <email@hidden>
    • Re: [CoreData] Background Insertion
      • From: Andrew Kimpton <email@hidden>
References: 
 >[CoreData] Background Insertion (From: Andrew Kimpton <email@hidden>)
 >Re: [CoreData] Background Insertion (From: Dave Fernandes <email@hidden>)
 >Re: [CoreData] Background Insertion (From: Andrew Kimpton <email@hidden>)
 >Re: [CoreData] Background Insertion (From: "Marcus S. Zarra" <email@hidden>)
 >Re: [CoreData] Background Insertion (From: Andrew Kimpton <email@hidden>)
 >Re: [CoreData] Background Insertion (From: "Marcus S. Zarra" <email@hidden>)

  • Prev by Date: Re: core data newbie Q
  • Next by Date: How is a bound NSArrayController so stealthy?
  • Previous by thread: Re: [CoreData] Background Insertion
  • Next by thread: Re: [CoreData] Background Insertion
  • Index(es):
    • Date
    • Thread