How do I add variables to a string? (Swift)
1 answer
In quick succession, string interpolation is done using \()
within strings. For example:
let x = 10
let string = "x equals \(x) and you can also put expressions here \(5*2)"
so for your example do:
var age:Int=1
var pet:String="dog"
lblOutput.text = "Your \(pet) is \(age) years old!"
+18
source to share