• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Foundation tool question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Foundation tool question
      • From: Rob Rix <email@hidden>
References: 
 >Re: Foundation tool question (From: Rob Rix <email@hidden>)

  • Prev by Date: Cocoa for "platform independence"???
  • Next by Date: Re: BSD Cocoa GUI Examples - where?
  • Previous by thread: Re: Foundation tool question
  • Next by thread: Re: Foundation tool question
  • Index(es):
    • Date
    • Thread