Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate String and Integer in Swift

I would have expected concatenation between different types to be straightforward in Swift, but apparently not. What is the workaround for this?

var boy = "Bart Simpson"
var age = 7
print(boy + " is " + age)
like image 611
Stamp Avatar asked Nov 30 '22 10:11

Stamp


1 Answers

very easy, wrap all printable objects in \( )

let boy = "Bart Simpson"
let age = 7
print("\(boy) is \(age)")
like image 145
vadian Avatar answered Dec 01 '22 23:12

vadian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!