Xcode: Dividing long NSString constants over multiple lines
Posted: | Author: Jörn | Filed under: Objective-C, Xcode | Tags: NSString | No Comments »Just a little Objective-C “trick” to make long NSString constants a little bit more readable in your Code:
To break a part of the long string to a new line you have to wrap it in quotation marks. The compiler will then put it back together to one long string.
So instead of doing this:
NSString *htmlStr = @"PageTitle
Hello World
";
You could do this:
NSString *htmlStr = @""
""
"PageTitle "
""
""
"Hello World
"
""
"";
Of course the cleanest thing to do would be to separate the html code completely from your Objective-C code by putting it into a separate HTML file and load that into a string. But hey, who wants to be perferct all the time?