Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

16.2. Using NSThread

There are several different ways of creating new threads in Objective-C. The first of these is using the NSThread object.

16.2.1. Creating threads

To use the NSThread class to create a thread, you can either use the factory method +detachNewThreadSelector:toTarget:withObject:, or you can use the standard initializer, -initWithTarget:selector:object:. In the case of the former method, the thread will be created and launched running the code provided by the selector and target. In the case of the latter method, the thread will be initialized but won't actually be launched until you call the -start method. Listing 16.5 shows an example of creating a thread using the factory method.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint