2

I am not able to understand difference between calling a function in background like

[self performSelectorInBackground:@selector(getFriendFaceBookList) withObject:nil];

and calling the same function in a Thread :

[NSThread detachNewThreadSelector:@selector(getFriendFaceBookList) toTarget:self withObject:nil];

Which one is the best way to work in non ARC app.

Thanks

Vinod Singh
  • 1,374
  • 14
  • 25
  • 2
    Don't use either of these. Instead, dispatch the work to a global queue (which will run concurrently with the main thread). – Jason Coco Sep 25 '12 at 06:47
  • Thanks for your quick reply. How can use global queue ? – Vinod Singh Sep 25 '12 at 06:51
  • Unfortunately, I can't add links at the moment, hopefully another poster can/will, but check out the Concurrency Programming Guide and the Grand Central Dispatch reference in your documentation. It is available with iOS 4.0+ – Jason Coco Sep 25 '12 at 06:54
  • @JasonCoco Why should not we use any of these? – Ilker Baltaci Sep 25 '12 at 06:56
  • 1
    @IlkerBaltaci The note was more to the original poster, but in general, since you have to configure these threads and pay the costs associated with spawning thread in the kernel (on a resource limited device), they are not the best way to perform tasks in the background. If you have a long-running task that needs its own thread, these are not the methods that will do that for you. There's no real reason to use them anymore with the introduction of GCD, and if you have to ask what the difference is, you should be using GCD instead. – Jason Coco Sep 26 '12 at 17:00

1 Answers1

1

They're identical. See Documentation

performSelectorInBackground:withObject: The effect of calling this method is the same as if you called the detachNewThreadSelector:toTarget:withObject: method of NSThread with the current object, selector, and parameter object as parameters.

Hope it helps.

Anshuk Garg
  • 1,540
  • 12
  • 14