【问题标题】:Swift three double quotesSwift 三个双引号
【发布时间】:2017-10-05 23:39:07
【问题描述】:

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

我做错了什么?

【问题讨论】:

  • 这是 Swift 4 和 Xcode 9 的全新版本。您使用的是什么版本的 Xcode?​​span>
  • 可能是操场问题。它们并不总是 100% 准确地表示语言。 Typescript 的操场有一些小问题。
  • 我使用的是 Xcode 8

标签: swift swift-playground


【解决方案1】:

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

【讨论】:

  • 鉴于它指向第一行,而不是最后一行,这是最有意义的。
猜你喜欢
  • 2013-07-12
  • 2019-11-02
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
  • 2011-12-08
  • 1970-01-01
相关资源
最近更新 更多