views:

125

answers:

2

I'm confused about the concept of "threads" in iPhone development:

  • Why are threads necessary / useful?
  • How can threads be used in Objective-C?
A: 

You need multi-threading in objective c because sometimes you need functions/code to run "in the background" (read: on another thread). For instance (but not explicitly) you might need to download large amounts of data off the internet (a picture, or a video).

In this case running the download on the 'main' thread will cause the iphone to freeze before the download is complete. So you use multi-threading to download the data AND let the iphone work all at the same time.

There are lots of ways to do multithreading in objective-c. To be honest you need to look it up yourself, we're not here to just spoonfeed you.

Things to look up are: NSURLConnection and the method [self performSelector:onThread:...]

Thomas Clayson