Re: Foundation tool question
Re: Foundation tool question
- Subject: Re: Foundation tool question
- From: John Hörnkvist <email@hidden>
- Date: Wed, 30 May 2001 18:18:28 +0200
On Wednesday, May 30, 2001, at 05:53 PM, Rob Rix wrote:
Ah, yes, this works very well. So, can I accept input from stdin after
my NSRunLoop is running (and should this go in the NS_DURING section?)?
NS_DURING is just for exception handling.
I think you should use NSFileHandle; it seems like
"readInBackgroundAndNotify" would be suitable.
Something like this in your "main":
NSFileHandle* handle=[[NSFileHandle fileHandleWithStandardInput] retain];
[handle readInBackgroundAndNotify];
[[NSNotificationCenter defaultCenter] addObserver:someObject
selector:@selector(handleInput:)
name:NSFileHandleReadCompletionNotification object: handle];
[[NSRunLoop currentRunLoop] run];
[handle release];
And then add a method like this somewhere:
- (void) handleInput:(NSNotification*)notification
{
NSFileHandle* handle=[notification object];
NSData* dataRead=[[notification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
// ** Process the data somehow...
// ** Reschedule the file handle
[handle readInBackgroundAndNotify];
}
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com