Re: Avoiding temp file
Re: Avoiding temp file
- Subject: Re: Avoiding temp file
- From: "Louis C. Sacha" <email@hidden>
- Date: Thu, 1 Jul 2004 16:42:48 -0700
Hello...
Assuming your document class has distinct types for the different
types of data, all you have to do is implement writeToFile:ofType:
something like this
- (BOOL)writeToFile:(NSString *)path ofType:(NSString *)docType
{
if ([docType isEqualToString:@"DocTypeYouWantToWriteToFile"])
{
return [[mainArrayController content]
writeToFile:@"/tmp/temp.xml" atomically:YES];
}
else
{
[super writeToFile:path ofType:docType];
}
}
Any document types other than @"DocTypeYouWantToWriteToFile" will
fall through to the standard NSDocument implementation of
writeToFile:ofType: which will call dataRepresentationOfType: and
then write out the result... If you can't distinguish between the
kinds of data based on the type, you'll need some other sort of test,
but the basic concept is the same.
Hope that helps,
Louis
Hello,
Is there a way where I can avoid writing to a temporary file?
- (NSData *)dataRepresentationOfType:(NSString *)aType {
// A bit (w)hacky this way!!!
[[mainArrayController content] writeToFile:@"/tmp/temp.xml"
atomically:YES] ;
return [[NSString stringWithContentsOfFile:@"/tmp/temp.xml"]
dataUsingEncoding:NSUTF8StringEncoding];
}
I want to use dataRepresentationOfType: instead of
writeToFile:ofType: as another of my filetypes is done most easily
returning NSData. I suppose having both methods at the same time
doesn't work, right?
Thanks,
Johan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.