NSError and [NSTextStorage readFromURL:options:documentAttributes:error:]
NSError and [NSTextStorage readFromURL:options:documentAttributes:error:]
- Subject: NSError and [NSTextStorage readFromURL:options:documentAttributes:error:]
- From: Jesse Grosjean <email@hidden>
- Date: Thu, 10 Jul 2008 08:21:19 -0400
My should open any kind of text file, so I accept wild-card file
extensions. But if the user drops an image or some non text file onto
my app then I want it to give a nice error response like TextEdit
does. Text edit says:
The document “test.zip” could not be opened. The file is not in the
right format.
The file might be corrupted, truncated, or in a different format than
you expect.
After some investigation it looks like that error message is actually
being created by [NSTextStorage's
readFromURL:options:documentAttributes:error:] method. So in my app I
decided to use that same method for reading text, unfortunately I
can't get it to work in my program, though I CAN get it to work if I
create a new mini test project. I'm trying to figure out what the
difference could possibly be. If I run this exact code in both
applications:
NSURL *url = [NSURL fileURLWithPath:@"/Users/jesse/Desktop/test.zip"];
NSTextStorage *storage = [[NSTextStorage alloc] init];
NSError *myError = nil;
if (![storage readFromURL:url options:nil documentAttributes:nil
error:&myError]) {
NSLog([myError description]);
}
Then in my main app this is printed out:
Error Domain=NSCocoaErrorDomain Code=259 UserInfo=0x10d8e40 "(null)"
While in the text app this full error message gets printed out:
Error Domain=NSCocoaErrorDomain Code=259 UserInfo=0x1043500 "The file
“test.zip” could not be opened because it is not in the right format."
Does anyone know what could cause this, or how to fix it? The end
result is that in my test app when a document fails to open it gets a
nice TextEdit style description of what happened. But in my real app
the message is just "The document “test.zip” could not be opened. "
Jesse_______________________________________________
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