swift - use backslash to add the value in the string

There’s an even simpler way to include values in strings: Write the value in parentheses, and write a backslash (\) before the parentheses. This is known as string interpolation.

  1. let apples = 3
  2. let oranges = 5
  3. let appleSummary = "I have \(apples) apples."
  4. let fruitSummary = "I have \(apples + oranges) pieces of fruit."
posted @ 2016-03-08 14:46  facial  阅读(147)  评论(0编辑  收藏  举报