0

I've got a method that will sync my app with the online API. When running this sync script the reponses of the app are delayed. I tried using:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { 
 self.syncEverything() 
}

This doesn't has any effect on the speed. Could someone tell me the right approach for this problem?

EDIT

I changed the code, my syncing script is now using a different context then the context of the main thread. When the syncing is complete, I merge the contexts. Still the syncing is slowing down the gui.

Below my CPU activity when syncing, does this mean everything is running on the main thread?

enter image description here

In some of the classes used in "syncEverything()" is UIKit imported, could this be the cause of the delay?

Jab
  • 821
  • 3
  • 13
  • 26
  • 1
    What does `syncEverything()` do? If anything in `syncEverything()` updates the UI then performance will be terrible or crash. – Jeffery Thomas Jun 02 '15 at 19:19
  • It does a lot of JSON parsing and it updates core data objects. At the end it calls: NSNotificationCenter.defaultCenter().postNotificationName("finished", object: nil) . – Jab Jun 02 '15 at 19:43
  • Multithreaded Core Data get complicated. see: http://stackoverflow.com/questions/24657437/core-data-background-context-best-practice – Jeffery Thomas Jun 02 '15 at 19:51
  • As a simpler alternative, you can switch to [MagicalRecord](https://github.com/magicalpanda/MagicalRecord) for all your Core Data needs. It has simple [background thread handling](https://github.com/magicalpanda/MagicalRecord/wiki/Working-with-Managed-Object-Contexts). – Jeffery Thomas Jun 02 '15 at 19:57
  • I changed the code, my syncing script is now using a different context then the context of the main thread. When the syncing is complete, I merge the contexts. Still the syncing is slowing down the gui. Any suggestions? – Jab Jun 04 '15 at 19:04
  • Again, without seeing `syncEverything()`, I can't say why, but the graph you shown above has almost all of the activity on the main thread. – Jeffery Thomas Jun 05 '15 at 00:25

0 Answers0