Playground执行失败:MyPlayground.playground:19:33:错误:无法找到类型' Int'接受类型'(字符串)'的参数列表 var languagesLearnedNum:Int? = Int(languagesLearned) ^
var languagesLearned: String = "3"
var languagesLearnedNum: Int? = Int(languagesLearned)
if let num = languagesLearnedNum {
println("It is a Number")
}else {
println("It is not a Number")
}
答案 0 :(得分:1)
使用languagesLearned.toInt()
。但是,如果您没有使用Swift 2.0,则可以使用Int(languagesLearned)
但不能使用println()
。