let longString = """
When you write a string that spans multiple
lines make sure you start its content on a
line all of its own, and end it with three
quotes also on a line of their own.
Multi-line strings also let you write "quote marks"
freely inside your strings, which is great!
"""
Swift 4通过提供多行字符串文字支持解决了这个问题。要开始字符串字面量,添加三个双引号(" " " ")并按回车键,按回车键后开始写带有任何变量的字符串,换行符和双引号,就像你在记事本或任何文本编辑器中写的那样。要结束多行字符串文字再次写入(" " ")在新行。
参见下面的例子
let multiLineStringLiteral = """
This is one of the best feature add in Swift 4
It let’s you write “Double Quotes” without any escaping
and new lines without need of “\n”
"""
print(multiLineStringLiteral)
String(swiftLintMultiline:
"Lorem ipsum dolor sit amet, consectetur adipiscing",
"elit. Ut vulputate ultrices volutpat. Vivamus eget",
"nunc maximus, tempus neque vel, suscipit velit.",
"Quisque quam quam, malesuada et accumsan sodales,",
"rutrum non odio. Praesent a est porta, hendrerit",
"lectus scelerisque, pharetra magna. Proin id nulla",
"pharetra, lobortis ipsum sit amet, vehicula elit. Nulla",
"dapibus ipsum ipsum, sit amet congue arcu efficitur ac. Nunc imperdi"
)