Swift 三双引号 [英] Swift three double quotes

查看:46
本文介绍了Swift 三双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to Swift. The docuentation says: Use three double quotes (""") for strings that take up multiple lines. Indentation at the start of each quoted line is removed, as long as it matches the indentation of the closing quote. For example:

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 中,它显示了一个错误:

However, I copied this example and pasted in my xcode playground and it shows an error:

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

我做错了什么?

推荐答案

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

I assume you are using Xcode 8 or earlier. Multi line String Literals have been implemented in Swift 4. You can only use them with Xcode 9 Beta or by including the open source Swift 4 toolchain in your Xcode at the moment.

这篇关于Swift 三双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆