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 usingnsmainqueueconfinementornsprivatequeueconfinementand callchangedvaluesusingperformblock:orperformblockandwait:block gets changes. changed values , copy them outside of core data. make sure access core data in 1 of blocks.changedvaluesuseless after save, so... - if use
changedvalues, you'll need usensmanagedobjectcontextobjectsdidchangenotificationnotified of changes, can happen lot, so... - it's better use
nsmanagedobjectcontextwillsavenotification, happens when you're saving changes. there's nouserinfoyou'll have @ notification'sobject(whichnsmanagedobjectcontext) , useinsertedobjects,updatedobjects, ,deletedobjectsfind 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