how can i write a UNICODE text file in cocoa?

Discussion in 'Mac Programming' started by newformac, Aug 10, 2011.

  1. newformac macrumors regular

    Joined:
    May 24, 2011
    #1
    Hi all,

    can u please help me to write a unicode text file in cocoa application?

    thanks.
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    This isn't actually possible because you can't write a unicode text file. You can though write an NSString to a text file using a particular Unicode encoding. The most common encoding is UTF-8.

    Check out writeToURL:atomically:encoding:error: in the NSString Class Reference. Possible encodings are listed under String Encodings in the Constants sections. For example, you write using UTF-8 by using NSUTF8StringEncoding.
     
  3. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    Your question is impossible to answer until you tell us exactly what you mean by "unicode text file". Do you mean UTF-8, UTF-16, UTF-16LE or UTF-16BE, UTF32 or what? In other words, what exactly are you trying to achieve?
     
  4. newformac thread starter macrumors regular

    Joined:
    May 24, 2011
  5. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #5
    Look at the methods in NSString. Check if there is one that allows you to write an NSString to a file. And see if there is one that lets you specify the encoding as well.
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney

Share This Page