What is String Interpolation in swift?

0 votes
60 views
asked Mar 3, 2015 in Swift by jonathan (3,105 points)
Hi All

  What is String Interpolation in swift?

1 Answer

0 votes
answered Mar 3, 2015 by kalpana (3,995 points)

Hi Jonathan

String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash:

  • let multiplier = 3
  • let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
  • // message is "3 times 2.5 is 7.5"
...