斯威夫特三个双引号

jre*_*t56 14 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.
"""
Run Code Online (Sandbox Code Playgroud)

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

Playground execution failed: error: SwiftBasics.playground:9:19: error: 
unterminated string literal
let quotation = """
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

Jen*_*der 27

我假设您使用的是Xcode 8或更早版本.多行字符串文字已在Swift 4中实现.您只能在Xcode 9 Beta中使用它们,或者在Xcode中包含开源Swift 4工具链.