• 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
Save in Core Data from another thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Save in Core Data from another thread


  • Subject: Save in Core Data from another thread
  • From: malcom <email@hidden>
  • Date: Tue, 30 Oct 2007 01:57:15 +0100

Hello,
I've a program that receive lots of data from a network connection.
As data arrives I've used Core Data insertObject in order to put a description of data into my managed context and a complete data reference in a file handle (core data is basically an index).
This work pretty well but while when I try to fetch data from another persistent store when the first still receive data it works fast if I click on a fetched item it takes lots of time, and I can see the contents only when the other threads has finished to get data.
I've tried this solution:


- (void) storeList:(NSArray *)listOfMessages {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int k;
NSManagedObjectContext *ctx = [self newIstanceManagedObjectContext];
for (k=0;k < [listOfMessages count]; k++) {
[self _storeArticleDataInThisArchive: [listOfMessages objectAtIndex:k] inCtx: ctx];
}
[listOfMessages removeAllObjects];
[pool release];
}


where newIstanceManagedObjectContext creates a new ctx:

- (NSManagedObjectContext *) newIstanceManagedObjectContext {
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
NSManagedObjectContext *_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setRetainsRegisteredObjects:YES];


		[_managedObjectContext setPersistentStoreCoordinator: coordinator];

		return [_managedObjectContext autorelease];
    }
	return nil;
}

Unfortunatly it does not works because on saving the results is this:

repareForSave:: save for NSSQLCore 0xf0b1670 is already in progress
Error Domain=NSCocoaErrorDomain Code=259 UserInfo=0x169235d0 "The file “test” could not be opened because it is not in the right format."


What's wrong in my code? How can I perform a thread-safe saving/ inserting?
Thanks_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please 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: Save in Core Data from another thread
      • From: malcom <email@hidden>
    • Re: Save in Core Data from another thread
      • From: Chris Hanson <email@hidden>
  • Prev by Date: Re: Collection was mutated while being enumerated
  • Next by Date: Re: Figuring out Interface Builder 3.0
  • Previous by thread: Re: Grabbing what's behind a window
  • Next by thread: Re: Save in Core Data from another thread
  • Index(es):
    • Date
    • Thread