ios - How to prevent temporaryContext run concurrently with migratePersistentStore -


i have code part call migratepersistentstore , want prevent temporarycontext in same time, how?

my idea based on semaphore , dispatch_group.

code a:

dispatch_group_wait(dgloadmain, dispatch_time_forever) dispatch_semaphore_wait(semaloadmain, dispatch_time_forever)  mainmoc!.performblockandwait({      mainmoc!.persistentstorecoordinator!.migratepersistentstore(/* ... */) })  dispatch_semaphore_signal(semaloadmain) 

code b:

dispatch_group_enter(dgloadmain) dispatch_semaphore_wait(semaloadmain, dispatch_time_forever) dispatch_semaphore_signal(semaloadmain) let context = nsmanagedobjectcontext(concurrencytype: .privatequeueconcurrencytype) context.parentcontext = mainmoc  var context: nsmanagedobjectcontext context.performblockandwait({      // .. code not want run when migrating persistent store      context.save(nil) })  mainmoc.performblockandwait({      mainmoc.save(nil) })  dispatch_group_leave(dgloadmain) 

what think it? bette solution? possible use dispatch_barrier_async in case?

a far better solution design application not necessary. blocking entire application (including ui thread) doing while migration happening.

better develop state engine, migration in background , notify ui when migration complete. way application responsive system (and won't killed os) , can provide potential status updates user.

what doing here begging os kill app mid migration.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -