iphone - Core Data with parallel operations -


i new core data world , using ios 4 base framework , using core data perform operation against local sqlight db, designing offline application @ point when user come online need pull updated data server , push same local db, plus @ same time user might performing inserts , updated same db through ui well.

so there 2 sets of operations happening on same db on same time

1) user doing inserts or updates through ui views

2) synchronization engine running in background might pulling data , pushing local db

in such situation there might issue shared managed context being saved [with [context save:&error];], because there possibility context might end saving wrong data.

i think of having 2 solutions same

1) creating persistent store pointing same db, doing lead high memory consumption on device

2) creating different thread synchronization engine, not sure how deal it.

can guys please shade light on this, or thinking in wrong direction?

thanks ajay sawant

personally, use threads. (actually, i'd use nsoperation that's fancy thread).

never share managed context between threads.

if want transactions separate (i.e. background updates etc), use different managed object context each one.

you should use 1 persistentstorecoordinator create managedobjectcontext each thread in app.

this means can't pass managed objects between threads it's pass objectids i.e. if want tell main thread has been done :

// on background thread . . .  [managedobjectcontext save:nil];  nsdictionary *userinfo = [nsdictionary dictionarywithobjectsandkeys:[mything objectid], @"id", nil]; [nsnotificationcenter defaultcenter] postnotificationname:@"something-happened" object:self userifno:userinfo]; 

on main thread should use objectwithid method new managed object main thread's managedobjectcontext.

see document more details


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -