• 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: NSDocument: how to save document as a simple text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument: how to save document as a simple text file


  • Subject: Re: NSDocument: how to save document as a simple text file
  • From: Ali Ozer <email@hidden>
  • Date: Wed, 24 Apr 2002 09:44:21 -0700

Well I have written a document based Cocoa app which reads
data from a thermometer (via a USB to Serial Adapter).

Now I just want to save the data in text format instead of RTF,
So I can open it in Bbedit or read it in my favorite graph app.
I know how to save it in RTF though.

If the contents of your document can be expressed as a simple NSString, you can write that to a file with writeToFile:atomically:. You can get the string in a text object by doing [textView string].

Or you can be more explicit about the encoding by converting to an NSData first, then writing that. This is twice as much work, but the preferred way:

NSData *data = [string dataUsingEncoding: yourEncoding];
if (data) [data writeToFile: fullPath atomically: YES];

You can use UTF-8, or MacRoman, or whatever's appropriate for the clients who will load this document.
Note that MacRoman conversion might fail (that is, you will get back a nil data) if the string contains characters that cannot be expressed in MacRoman. If it's all ASCII or Western European, it should work.

Ali
_______________________________________________
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: 
 >NSDocument: how to save document as a simple text file (From: Gilles Celli <email@hidden>)

  • Prev by Date: libjpeg
  • Next by Date: Re: Printing example in Cocoa Programming for MacOS X
  • Previous by thread: NSDocument: how to save document as a simple text file
  • Next by thread: NSDocument: how to save document as a simple text file
  • Index(es):
    • Date
    • Thread