multithreading - Tracking changes made to a NSManagedObject on a different thread -
i want send changes made nsmanagedobject
server , want in background.
therefor, setup background thread own nsmanagedobjectcontext
registers nsmanagedobjectcontextdidsavenotification
. however, cannot access changedvalues
on userinfo
's nsinserted/updated/deletedobjectskey
, because it's on different thread.
how can done then?
the easy way is: don't bother changedvalues
. send attributes of managed object changes. overhead not much, , code simpler.
if want send values of attributes have changed, gets more complicated:
- you can use
changedvalues
, long usingnsmainqueueconfinement
ornsprivatequeueconfinement
and callchangedvalues
usingperformblock:
orperformblockandwait:
block gets changes. changed values , copy them outside of core data. make sure access core data in 1 of blocks.changedvalues
useless after save, so... - if use
changedvalues
, you'll need usensmanagedobjectcontextobjectsdidchangenotification
notified of changes, can happen lot, so... - it's better use
nsmanagedobjectcontextwillsavenotification
, happens when you're saving changes. there's nouserinfo
you'll have @ notification'sobject
(whichnsmanagedobjectcontext
) , useinsertedobjects
,updatedobjects
, ,deletedobjects
find out objects have changed.
with this, can access changed values, copy them whatever data structure you're using hold outgoing changes, , send them.
but i'd go ignoring changedvalues
if it's @ possible.
Comments
Post a Comment