Re: Document file read, but -readFromData:(etc) has error.
Re: Document file read, but -readFromData:(etc) has error.
- Subject: Re: Document file read, but -readFromData:(etc) has error.
- From: "I. Savant" <email@hidden>
- Date: Thu, 13 Aug 2009 17:21:06 -0400
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError
{
NSLog(@"readFromData has been called, typeName is: %@\n",
typeName);
if ( outError != NULL ) {
NSLog(@"outError is not null");
NSLog(@"Going to call NSError\n");
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain
code:unimpErr userInfo:NULL];
NSLog(@"Read error -- outError is: %@\n\n", *outError);
[self setInputData:[[NSString alloc]
initWithData:data
encoding:NSUTF8StringEncoding]];
[self convertData];
return NO;
}
Have you provided the complete implementation for this method? If
so, you seriously need to re-read this:
http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Documents.html#
But what is the unimplemented core routine?
This line makes it clear you're not reading the documentation. The
docs say of this method:
"The default implementation of this method throws an exception because
at least one of the three reading methods (this
method,readFromURL:ofType:error:, readFromFileWrapper:ofType:error:),
or every method that may invoke readFromURL:ofType:error:, must be
overridden."
The core routine is the one you're trying to implement ... by
returning NO, the system is displaying this pre-generated error.
In your code (which makes no sense to me whatsoever), you appear to
be asking if there's an error (which there is, by default, per the
docs), then going ahead and reading in the file (without checking if
that call even succeeded), then returning NO, signaling the document
could not be read. What happens if there *is* no error is anyone's
guess because you don't appear to be returning anything in that case
(if the method says it returns something, it had better return
something). Of course you'll never hit that case with how you're
presently implementing it ...
Usually your method would have if cases for each of your document
types (which return yes on success or setting the error on failure)
and your last line in that method would return NO (a catch all for
"not the right doc type" and "doc type failed to open") so your
customized error will be presented to the user.
Seriously - read the documentation. It's all there in great detail.
--
I.S.
On Aug 13, 2009, at 5:07 PM, John Velman wrote:
I'm writing a simple throw away program to transform data format
from a
text file to a text file. I decided to use a Cocoa Document class for
practice, instead of (for example) perl.
Using -readFromData:ofType:Error: storing the data as a string, and
then
converting the string works fine (except the program just stalls
afterwards) and has to be killed.
In trying to track this down, I put a bunch of NSLog's in, and ended
up
with this (boiler plate comments ommitted):
__
"convertData" is the method that does the format conversion. It has
ample
NSLog statments so I can see that it is being converted properly.
My debug console gives:
2009-08-13 13:44:50.376 TransformKaiser[1419:10b] readFromData has
been called, typeName is: Kiaser History Convert
2009-08-13 13:44:50.378 TransformKaiser[1419:10b] outError is not null
2009-08-13 13:44:50.378 TransformKaiser[1419:10b] Going to call
NSError
2009-08-13 13:44:50.380 TransformKaiser[1419:10b] Read error --
outError is: Error Domain=NSOSStatusErrorDomain Code=-4 "Operation
could not be completed. (OSStatus error -4.)" ( / / unimplemented
core routine)
(Could have spelled Kaiser correctly, but what the heck, this was
supposed
to be a one run throw away program.)
and I get an alert message that says: "The document “testFile.txt”
could
not be opened." I suppose this is due to returning NO.
But what is the unimplemented core routine?
I'm using Xcode 3.1.3, on OS X 10.5.8, Intel core 2 duo. My active
architecture is i386, sdk is 10.5, build configuration is Debug.
Thanks,
John Velman
_______________________________________________
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
_______________________________________________
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