NSDocument window opens - even if the document didn't read properly.
NSDocument window opens - even if the document didn't read properly.
- Subject: NSDocument window opens - even if the document didn't read properly.
- From: Pascal Harris <email@hidden>
- Date: Sun, 29 Jul 2012 18:53:16 +0100
I hope that someone here might be able to help me with a couple of queries.
1. I'm trying to open a document (NSDocument). If the file is good then my program opens it without problem. If the document fails to parse correctly then the NSDocument window still opens - but it opens empty. Of course, if parsing of the document fails then I want the document window not to open at all. The document data gets read as so and if it fails then I return NO - the document window still opens though. Can anyone suggest what I might have missed or messed up?
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
BOOL success = NO;
success = [self loadTextViewWithInitialData: data];
if (!success)
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* URLString = [[[paths objectAtIndex:0] stringByAppendingString:[self fileURL].lastPathComponent]stringByAppendingString:@".bad"];
NSURL* destinationURL = [NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
BOOL success = [[NSFileManager defaultManager] copyItemAtURL:[self fileURL] toURL:destinationURL error:nil];
}
return success;
}
2. If the document fails to open then I want to copy it to a new location, with a new extension (see above). This fails. I can't think why!
_______________________________________________
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