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 using nsmainqueueconfinement or nsprivatequeueconfinement and call changedvalues using performblock: or performblockandwait: 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 use nsmanagedobjectcontextobjectsdidchangenotification notified of changes, can happen lot, so...
  • it's better use nsmanagedobjectcontextwillsavenotification, happens when you're saving changes. there's no userinfo you'll have @ notification's object (which nsmanagedobjectcontext) , use insertedobjects, 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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -