i want use multithreading core data. parse xml-file in nsmanageobject
s. use code below , runtime error can use -performblock: on nsmanagedobjectcontext created queue
. what's wrong?
//xmlparser - (void)main { dispatch_queue_t queueb = dispatch_queue_create("create books", null); dispatch_async(queueb, ^{ // opening xml // ... nsmanagedobjectcontext* context = [[nsmanagedobjectcontext alloc] init]; [context setpersistentstorecoordinator:maincontext].persistentstorecoordinator]; [context performblock:^{ // ... [self _parsenode:container_node appendto:books incontext:context]; // ... nserror* error = nil; [context save:&error]; [maincontext performblock:^{ nserror* parenterror = nil; [maincontext save:&parenterror]; }]; }]; [context release]; }); dispatch_release(queueb); } - (int)_parsenode:(axlnode*)inode appendto:(nsmutablearray*)ioarray incontext:(nsmanagedobjectcontext*)context { // ... [context executefetchrequest:request error:&error]; //... }
performblock
can used managed object context (moc) of nsmainqueueconcurrencytype
or nsprivatequeueconcurrencytype
. in case, should create context with
nsmanagedobjectcontext *context = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsprivatequeueconcurrencytype];
and there no need create dispatch queue or use dispatch_async()
. moc creates , manages own queues, , performblock
ensures block executed on moc's queue.
Comments
Post a Comment