DekGenius.com
[ Team LiB ] Previous Section Next Section

NSRunLoop Mac OS X 10.0

This class manages input sources for a thread. In Cocoa, input sources may include mouse and keyboard events, as well as NSPorts, NSTimers, and NSConnections. NSRunLoop serves as an interface between an application and the rest of the operating system. When events from the mouse, keyboard, or other peripherals are received in the operating system, they are forwarded to the active application through that application's run-loop. The run-loop monitors all of its input sources continuously for events, and dispatches them to the appropriate object in an application. For more information on NSRunLoop and event handling in Cocoa, see Chapter 3.

Every instance of NSApplication creates and manages its own run-loop. This is the main run-loop of the application. Because this run-loop is created for us, we don't need to use any of the NSRunLoop APIs. However, new threads do not have a run-loop object associated with them. For a thread to participate in event handling and notification from other run-loop sources, create a run-loop for any the thread. If you need to have access to a run-loop object, then you can obtain a pointer to the run-loop of the current thread by invoking the class method currentRunLoop. If you need to start your own run-loop in a thread, you must first create the run-loop using alloc and init, and send a run message to the run-loop object.

NSRunLoop objects are based on Core Foundation CFRunLoop objects. The method getCFRunLoop returns an NSRunLoop's underlying Core Foundation run-loop.

figs/cocn_1390.gif

@interface NSRunLoop : NSObject
 // Class Methods
   + (NSRunLoop *)currentRunLoop;
 // Instance Methods
   - (void)acceptInputForMode:(NSString *)mode beforeDate:(NSDate *)limitDate;
   - (void)addPort:(NSPort *)aPort forMode:(NSString *)mode;
   - (void)addTimer:(NSTimer *)timer forMode:(NSString *)mode;
   - (void)cancelPerformSelector:(SEL)aSelector target:(id)target argument:(id)arg;
   - (void)cancelPerformSelectorsWithTarget:(id)target;
   - (void)configureAsServer;
   - (NSString *)currentMode;
   - (CFRunLoopRef)getCFRunLoop;
   - (NSDate *)limitDateForMode:(NSString *)mode;
   - (void)performSelector:(SEL)aSelector target:(id)target argument:(id)arg order:(unsigned)order
        modes:(NSArray *)modes;
   - (void)removePort:(NSPort *)aPort forMode:(NSString *)mode;
   - (void)run;
   - (BOOL)runMode:(NSString *)mode  beforeDate:(NSDate *)limitDate;
   - (void)runUntilDate:(NSDate *)limitDate;

    [ Team LiB ] Previous Section Next Section