0

I am a newbie to iOS. I have a requirement where I need to fetch data from a local database and upload it to a server. This has to be done in the background when the internet connection is available. How can I proceed on this? I need a kick start.

I read that I can achieve this with help of NSThread, or GCD, but I don't get when each of those is most suitable. Can someone suggest the right way? A sample or pseudocode would help a lot.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
RockandRoll
  • 409
  • 5
  • 23

1 Answers1

1

here is what gcd code should look like:

dispatch_queue_t queue = dispatch_queue_create("queue_name", 0);
    dispatch_async(queue, ^(){
    // code
});

Since GCD uses blocks it allows you to capture the state of the local variables.

FYI: You might have searched on Google before posting to stackoverflow. Your query is very common and has been answered before. You might also consider looking at the apple documentation.

Venkat S. Rao
  • 1,110
  • 3
  • 13
  • 29
  • here is the apple link: https://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/ConcurrencyandApplicationDesign/ConcurrencyandApplicationDesign.html#//apple_ref/doc/uid/TP40008091-CH100-SW1 – Venkat S. Rao Feb 21 '13 at 18:53