Is there another, better way?
Also related to this, IIRC in C++ if you have two string literals it's
treated as if they were concatenated (not sure about C). Does this
hold in Objective-C(++) with NSString constants?
you also can’t include non-ASCII characters in NSString literals. my
workaround is to declare them as C strings, then convert to NSStrings at
runtime, if needed.
> Apparently, you cannot declare a multiline NSString constant (which is
> useful for, say, if you had an ultralong SQL statement that you want to
> break up over multiple lines to make it more readable). I've worked
> around it by using +stringWithFormat:, but that seems a bit tedious
> (and you have to keep track of how many pieces you have).
>
> Is there another, better way?
Probably the best way is to not hard-code them into your software.
Include them in a plist file in the bundle's resource folder or some
other solution.
--
I saw a truck today that had "AAA Batteries / Delivered and Installed" on the
side. My first thought was: That's a really weird business model. How many
inept people have urgent need of skinny little battery cells?
This holds true for me with stock GCC. I can't say offhand about
Apple's GCC.
@"This is a multiline NSString Constant\n"
"of course you can do it, and, in OS X 10.5,\n"
"Xcode 3, you can püt nön-äscïï characters in\n"
"your string constants. But: you must make sure\n"
"that you've correctly set the encoding of source\n"
"file of the project to UTF-8 in Xcode's View > Text menu.\n"
"Better: use NSLocalizedString() with ASCII keys, and values in a\n"
"UTF-16 strings file."
ig. that may be true, but i’d never do it! my philosophy is that source
files should always be plain old 7-bit ascii, the way god intended.
you can follow this rule and embed utf8 characters in C strings using escape
sequences.