连接println的混合类型

kmi*_*las 9 xcode concatenation println ios swift

我试图连接字符串和整数,并使用登录到控制台println.

println("Load number: " + webViewLoads)
Run Code Online (Sandbox Code Playgroud)

webViewLoads是'Int'类型.由于我在这里混合了两种类型,因此我收到错误并不奇怪:
Could not find an overload for 'println' that accepts the supplied arguments.

所以,我尝试将webViewLoads转换as为字符串:println("Load:"+ webViewLoads as String)

Grr ..错误仍然被抛出.

我怎样才能使这个简单的小连接起作用?

Mic*_*lum 22

你有几个选择.您可以从Int创建一个新的String并连接它,或者您可以使用字符串插值.

println("Load number: " + String(webViewLoads))
println("Load number: \(webViewLoads)")
Run Code Online (Sandbox Code Playgroud)