/* Okay here is a bit of code to demonstrate threads in Cocoa. These two methods would be in the same class. input is an outlet to an NSTextField in the interface, output is an outlet to a non-editable NSTextView. Make OKButton something that is called when an OK button next to the input field is pressed. All this does is it takes input and put it into output 60 times, 1 time per second. If this wasn't multithreaded then you wouldn't be able to minimize or hide the window or choose any menu items during the 60 second period that this thing is displaying the output.*/
- (IBAction)OKButton
{
[NSApplication detachDrawingThread: @selector (doSomething

toTarget: self
withObject: [[input stringValue] retain]];
}
- (void)doSomething

NSString *)inputString
{
NSAutoreleasePool* pool;
NSRange range;
int length,
i;
range.location = 0;
range.length = [inputString length];
for(i = 0;i < 60; i++)
{
pool = [[NSAutoreleasePool alloc] init];
[output replaceCharactersInRange: range
withString: inputString];
range.location += length;
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
[pool release];
}
[inputString release];
}
[This message has been edited by Dalgo (edited 01-26-2001).]