Re: reason for getting NSFileHandle:writeData exception
Re: reason for getting NSFileHandle:writeData exception
- Subject: Re: reason for getting NSFileHandle:writeData exception
- From: Chris Heimark <email@hidden>
- Date: Mon, 9 Jul 2007 19:19:27 -0400
Thanks for pointing out what should have been obvious to me. I simply
got caught up trying to simplify the problem to try to explain
origianl problem. This does indeed work:
>>>>>
NSData *someData = [NSData dataWithBytes:(const void *)"Please stop
biting me!\r" length:23];
[outputFileHandle writeData:someData];
<<<<<
BUT, it works in the context of the callback to the save panel OK. I
still have the original, more obscure problem, witness this exception:
>>>>>
2007-07-09 19:04:53.738 DisplayQuantisData[4621] *** -[NSCFString
writeData:]: selector not recognized [self = 0x3e5390]
2007-07-09 19:04:53.754 DisplayQuantisData[4621] Exception raised
during posting of notification. Ignored. exception: *** -
[NSCFString writeData:]: selector not recognized [self = 0x3e5390]
<<<<<
And here is the code that runs in an NSTask callback occurring as a
result of running an external command line program and trying to
absorb the binary results using an NSData object.
>>>>>
- (void)appendOutput:(NSData *)rngData
{
int dataLength = [rngData length];
// when this next line is commented out, the rest of the code works
as expected
// the exception occurs when uncommented.
[outputFileHandle writeData:rngData];
amountCollected += dataLength;
NSLog (@"Read bytes with total collected\n", dataLength,
amountCollected);
}
<<<<<
Here is how I set this all off when reading data from NSTask pipe...
- (void) getData: (NSNotification *)aNotification
{
NSData *data = [[aNotification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
if ([data length])
{
[controller appendOutput:data];
// we need to schedule the file handle go read more data in the
background again.
[[aNotification object] readInBackgroundAndNotify];
}
else
{
// We're finished here
[self stopProcess];
}
}
<<<<<<
Seems I may not be getting back an NSData item - I simply am unable
to resolve why...
Thanks for any wise guidance.
On Jul 9, 2007, at 4:55 PM, Brian Stern wrote:
On Jul 9, 2007, at 4:23 PM, Chris Heimark wrote:
I am getting a nasty little exception:
2007-07-09 16:18:41.294 DisplayData[4441] *** -[NSCFString bytes]:
selector not recognized [self = 0x2e02c]
In response to the following snippet of code:
[outputFileHandle writeData:@"Please stop biting me!\r"];
writeData takes an NSData* not an NSString*. The exception is
because NSString doesn't have a method named bytes.
If you really want to write strings to the file handle use
NSString's dataUsingEncoding method to convert the NSString to an
NSData object, or some other method to add your string to an NSData
object.
--
Brian Stern
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden