1.4. Strings and print to console
Swift allows you to write strings in two ways. The first one is, of course, the age-old String we declare inside " ". The next one is multiline strings which you can write inside """ """ (triple quotes on both sides).
An example of the first type is the greeting variable we have. Let's try to see what a multi-line string is.
Let's create a string like the following:
var multiline = """
I am a multiline String.
I might look weird, but I am really very simple.
At times I could be very useful!
"""After you define the String, if you look at the output area, you'll see that a character '\n' is added between two lines. '\n' denotes a new line. It means that the variable multiline contains a String that will be logically multiline and follows the exact format the user put in.
Now, you can use the command print() to display the output to the console. Let's put the following line of code:
print(multiline)It should display the following at the bottom (console output) of Xcode:

Now you get the full view of how a multiline String would get displayed.
Video
Last updated
Was this helpful?