Ad space (banner)
๐ŸŽObjective-C Lessons
Lesson 46 / 68

Multi-line text (joining adjacent string literals)

This lesson covers joining adjacent string literals in Objective-C, with the aim of building readable messages.

Inherited from C, adjacent string literals are joined automatically at compile time into a single string. Using that property lets you split a string across several lines in the source while it stays one string at run time.

The sample code writes three @"..." literals across separate lines as the argument to stringWithFormat:. The compiler joins them into one string, which lets you lay a long message out legibly.

A common early stumble is that the joining happens at compile time rather than at run time. It works only between fixed literals, so it cannot be used to assemble a string containing variables.

In professional work, this property is used to keep a long message template readable inside the code.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Objective-C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)