• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Avoiding temp file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Avoiding temp file (From: Johan Kool <email@hidden>)

  • Prev by Date: Re: Strategy to split up large class files?
  • Next by Date: Re: Mixing Objective-C and C++ in Xcode
  • Previous by thread: Avoiding temp file
  • Next by thread: Re: Saving arrays with NSUserDefaults?
  • Index(es):
    • Date
    • Thread