The docs on -[NSString stringWithFormat:] link to old docs on string format specifiers which say that “the %s specifier causes the characters to be interpreted in the system default encoding”. What the heck is the system default encoding? I tried googling it, and all I found was people saying that while a program may have a default encoding, the Mac OS does not.
What is default encoding for %s?
What the heck is the system default encoding?
That’s hard to pin down. Logically it should be UTF-8 but Cocoa predates the invention of UTF-8 and thus it can vary by platform (and, on macOS, based on user settings). There are APIs to get this encoding (for example, CFStringGetSystemEncoding) but my general advice is that you not rely on this. If you want to print a string, convert it to NSString first and then print that using %@. You are then in control of the encoding used for the conversation.
If want UTF-8 conversion, @(someCString) is your friend.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
FYI if you’re presenting localized content, you might want to use [NSString localizedStringWithFormat:] instead. Among other things it localizes number variables, and correctly displays bi-directional text.