• 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
Best way to save a simple text file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best way to save a simple text file?


  • Subject: Best way to save a simple text file?
  • From: Jean-Nicolas Jolivet <email@hidden>
  • Date: Fri, 16 Nov 2007 13:02:01 -0500

What would be the best way to save a simple NSString to a text file in a document based application?

Right now I am using the following (in writeToUrl:ofType:error method):
---------------------------------------------
NSData *data = [NSData dataWithBytes: [myString UTF8String] length:[myString length]];
BOOL writeSuccess = [data writeToURL:inAbsoluteURL atomically:NO];
---------------------------------------------


However, I was wondering... is it really necessary for me to convert my string to an NSData object before saving it? Isn't there any other way to do it? Also, what if I would like to support multiple languages (i.e. multiple encoding??)... right now the string is converted to UTF8...

So.. in other words...any other technique to save a simple NSString to a text file? (Same goes for opening... do I need to convert to NSData?? Assuming I want to do file opening in readFromUrl). There are many different examples, but they all do it a different way (and most are outdated...i.e. using deprecated methods)...

Thanks
_______________________________________________

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


  • Follow-Ups:
    • Re: Best way to save a simple text file?
      • From: Aki Inoue <email@hidden>
    • Re: Best way to save a simple text file?
      • From: Douglas Davidson <email@hidden>
    • Re: Best way to save a simple text file?
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: NSAnimatablePropertyContainer
  • Next by Date: Re: Best way to save a simple text file?
  • Previous by thread: Re: row numbers participating in a table drag
  • Next by thread: Re: Best way to save a simple text file?
  • Index(es):
    • Date
    • Thread