Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate mixed types for println

I am trying to concatenate a string and an integer, and log to the console using println.

println("Load number: " + webViewLoads)

webViewLoads is type 'Int'. As I'm mixing two types here, there is no surprise that I'm getting an error:
Could not find an overload for 'println' that accepts the supplied arguments.

So, I tried casting webViewLoads as a string: println("Load: " + webViewLoads as String)

Grr.. Error still thrown.

How can I make this simple little concatenation work?

like image 655
kmiklas Avatar asked Jun 12 '14 15:06

kmiklas


1 Answers

You have a couple of options. You can create a new String from the Int and concatenate it, or you can use string interpolation.

println("Load number: " + String(webViewLoads))
println("Load number: \(webViewLoads)")
like image 176
Mick MacCallum Avatar answered Oct 26 '22 12:10

Mick MacCallum