views:

170

answers:

1

I have long XML strings that I'm hard-coding into an iPhone project's unit tests.

It's pretty ugly having to escape all the quotes and line breaks -- for example:

NSString *xml = 
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<root>\
    <element name=\"foo\" />\
</root>";

It would be really nice to have a lower-friction way to do that.

I know Ruby has a great syntax for multiline literals... any suggestions for Objective-C?

+3  A: 

ObjC also has multi-line literals, and single-quotes are legal in XML:

NSString *xml = 
@"<?xml version='1.0' encoding='UTF-8'?>"
 "<root>"
    "<element name='foo' />"
 "</root>";

Note that this doesn't embed newlines in the string, which is slightly different from your code.

Rob Napier
You can use `\n` for a newline to force them to be in there.
Squeegy
The OPs code also doesn't embed newlines.
Georg Fritzsche