I am currently working on an application which is parsing some JSON data in the APPdelegate class when the location is changed.
My question is: ” How is the most appropriate way doing it ?” Currently when it is parsing the data the application is “frozen” until the data has been loaded.
I need some advice 🙂
Thanks
There are several ways of course, including
NSThread,NSOperationand old-fashionedlibpthread. But what I find the most convenient (especially for simple background tasks) islibdispatchalso called Grand Central Dispatch.Using dispatch queues you can quickly delegate a time-consuming task to a separate thread (or more precisely, execution queue – GCD decides whether it’s a thread or an asynchronous task). Here’s the simplest example:
The above code will read JSON data in a separate execution queue, not blocking the UI thread. This is just a simple example and there’s a lot more to GCD, so take a look at the documentation for more info.