Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.
|
Code View:
Scroll
/
Show All NSMutableDictionary *threadLocal = [[NSThread currentThread] threadDictionary];
[threadLocal setObject:[NSNotificationCenter new]
forKey:@"NotificationCenter"];
|