多行字符串字面量/Multi-line String Literals

When building a long string literal, you're encouraged to use the multi-line string literal syntax. Open the literal on the same line as the assignment but do not include text on that line. Indent the text block one additional level.

当创建一个较长的字符串字面量时,你可以使用多行字符串字面量的便利语法。在赋值语句处开始创建这个字符串字面量,但是不包含任何文字。真正的内容将在第二行出现并缩进一个层级。

推荐(Preferred):

let message = """
  You cannot charge the flux \
  capacitor with a 9V battery.
  You must use a super-charger \
  which costs 10 credits. You currently \
  have \(credits) credits available.
  """

不推荐(Not Preferred):

let message = """You cannot charge the flux \
  capacitor with a 9V battery.
  You must use a super-charger \
  which costs 10 credits. You currently \
  have \(credits) credits available.
  """

不推荐(Not Preferred):

let message = "You cannot charge the flux " +
  "capacitor with a 9V battery.\n" +
  "You must use a super-charger " +
  "which costs 10 credits. You currently " +
  "have \(credits) credits available."

不要使用 Emoji/No Emoji

Do not use emoji in your projects. For those readers who actually type in their code, it's an unnecessary source of friction. While it may be cute, it doesn't add to the learning and it interrupts the coding flow for these readers.

不要在工程里使用 Emoji。对于读者而言,输入这一类型的代码意义并不大。虽然看起来十分可爱,但它对于学习的帮助不大且会打乱输入代码的节奏。

不要使用 #imageLiteral 和 #colorLiteral/No #imageLiteral or #colorLiteral

Likewise, do not use Xcode's ability to drag a color or an image into a source statement. These turn into #colorLiteral and #imageLiteral, respectively, and present unpleasant challenges for a reader trying to enter them based on tutorial text. Instead, use UIColor(red:green:blue) and UIImage(imageLiteralResourceName:).

同样地,不要使用 Xcode 提供的 #colorLiteral 和# imageLiteral 来设置颜色或图像,这会给读者带来学习不好的体验。因此,推荐使用UIColor(red:green:blue)UIImage(imageLiteralResourceName:)

Made with in Shangrao,China By 老雷

Copyright © devler.cn 1987 - Present

赣ICP备19009883号-1