• 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: 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


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>)
 >Re: [CoreData] Background Insertion (From: Dave Hayden <email@hidden>)

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