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
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Threads > Thread-Specific Values

15.4. Thread-Specific Values

Sometimes you need a global variable, but only within the context of a specific thread. Each NSThread object has a threadDictionary property exactly for this purpose. The property is a mutable dictionary that your application can use to store whatever values it needs. The example in Listing 15-3 creates an NSNotificationCenter object for a single thread.

Example 15.3. Storing a Thread Specific Value

NSMutableDictionary *threadLocal = [[NSThread currentThread] threadDictionary];
[threadLocal setObject:[NSNotificationCenter new]
                forKey:@"NotificationCenter"];

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

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

  

Start a Free Trial