toiavalle toiavalle - 3 months ago 22
Swift Question

Multiline Strings in Swift

How can I create a multiline string in Swift?
This is what I tried:

var myMultilineString = "This is a " + "\n" + "multiline string"
print(myMultilineString)


I wanted it to print:


This is a

multiline string

Answer

If you want more than a line return between the strings but rather a real blank line, then you need two line feed characers.

var myMultilineString = "This is a " + "\n\n" + "multiline string"
print(myMultilineString)

enter image description here

Comments