斯威夫特三个双引号

时间:2017-06-06 18:31:23

标签: swift swift-playground

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

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 execution failed: error: SwiftBasics.playground:9:19: error: 
unterminated string literal
let quotation = """

我做错了什么?

1 个答案:

答案 0 :(得分:26)

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