Reputation: 343
Every one, As i am new to iPhone Application , now i want know how to use NSThread in my App, what is the use of NSThread.
Please and send me some example programs on that.
Upvotes: 4
Views: 13643
Reputation: 31722
Read the NSThread Documentation to know what it offer to developers.
Upvotes: 4
Reputation: 96937
Use NSThread
when you want a unit of computational work done without necessarily either waiting for other units to finish, or holding up other computational work.
You can put almost any work into a thread, if it is sensible to do so.
A good example is a network request, where you set up a thread to download data from, say, a web server. Your thread will fire a "handler" function when it has completed its work. The handler works with the downloaded data; for example, parsing XML data from a web service.
You would use a thread in this example, because you don't want the entire application to lock up while your app downloads data over the network and processes it. An NSThread
instance puts this unit of work into its own little "space" that allows the larger app to continue to interact with the user.
An example of where you do not want to use threads on the iOS platform is with UI updates (e.g., changing the state of any of the UIControl
widgets). All UI updates happen on the main thread. If you use your own threads with UI widgets, the behavior is unpredictable and, more often than not, will simply not work.
Upvotes: 11