Swift 三个双引号

Swift three double quotes

我是 Swift 的新手。文档说:对占用多行的字符串使用三个双引号 (""")。每个引用行开头的缩进都将被删除,只要它与结束引号的缩进相匹配。对于示例:

let quotation = """
Even though there's whitespace to the left,
the actual lines aren't indented.
Except for this line.
Double quotes (") can appear without being escaped.
I still have \(apples + oranges) pieces of fruit.
"""

但是,我复制了这个示例并粘贴到我的 xcode playground 中,它显示了一个错误:

Playground execution failed: error: SwiftBasics.playground:9:19: error: 
unterminated string literal
let quotation = """

我做错了什么?

我假设您使用的是 Xcode 8 或更早版本。 Multi line String Literals 已在 Swift 4 中实现。您只能将它们与 Xcode 9 Beta 一起使用,或者通过将开源 Swift 4 工具链包含在您的 Xcode 中那一刻。