• 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: stringWithFormat / Rendering Text (iOS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithFormat / Rendering Text (iOS)


  • Subject: Re: stringWithFormat / Rendering Text (iOS)
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 24 May 2012 08:48:05 -0700

On May 24, 2012, at 5:50 AM, Jason Teagle wrote:

> (I've since discovered that the %@ and @"xxx" way works just fine, so I'll stick with that.

Good :) The problem with using "%s" is that it doesn't work well with non-ASCII characters. Cocoa has to assume some character encoding to map the bytes to Unicode, and the rules for what encoding it chooses are both obscure and not very useful. (In short: it depends on the user's language/locale, and the default for English is the obsolete MacRoman encoding, not UTF-8 or even ISO-Latin-1.)

To reiterate: the only time you should use "%s" is if the C string you're passing in is guaranteed to be pure ASCII. Which is not very common.

In other circumstances, use "%@" and convert the C string to an NSString using -[NSString initWithCString:encoding:].

—Jens
_______________________________________________

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


References: 
 >applicationDidHide - Not Getting Triggered? (From: Jason Teagle <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Ken Thomases <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Jason Teagle <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Ken Thomases <email@hidden>)
 >stringWithFormat / Rendering Text (iOS) (From: Jason Teagle <email@hidden>)
 >Re: stringWithFormat / Rendering Text (iOS) (From: Conrad Shultz <email@hidden>)
 >Re: stringWithFormat / Rendering Text (iOS) (From: Jason Teagle <email@hidden>)

  • Prev by Date: Re: Multiple Inheritance
  • Next by Date: Re: NSWindowController subclasses, and retain cycles
  • Previous by thread: Re: stringWithFormat / Rendering Text (iOS)
  • Next by thread: Re: stringWithFormat / Rendering Text (iOS)
  • Index(es):
    • Date
    • Thread