Swift – Include Value of a Variable in String
To include value of a variable in a String in Swift, specify the variable in parentheses preceded by a back slash character.
The syntax to include value of a variable in a String is
"Value is \(x)"
x is a variable or a constant.
In the following program, we will initialize a variable
x with value of
10. We shall include this
x in a string, and print the string to console.
var x = 10 var str = "Age is \(x)" print(str)
In this Swift Tutorial, we learned how to include the value of a variable in a String in Swift programming, with the help of example program.