【发布时间】:2016-09-17 15:45:14
【问题描述】:
我对转换错误有点困惑。
我将我的项目从 Swift 2.3 迁移到 Swift 3.0
func updateCelsiusLabel() {
if let value = celsiusValue {
//This was the original code (that worked but is) failing after migration
//due to: Argument labels do not match any available overloads
celsiusLabel.text = numberFormatter.string(from: NSNumber(value))
//This is my code trying to fix this issue and the project is now compiling
//and everything is fine
celsiusLabel.text = numberFormatter.string(from: value as NSNumber)
}
else { celsiusLabel.text = "???"
}
}
起初我认为在 Swift 3.0 中,现在禁止转换 Type(value),但我检查了一下,我绝对没有收到编译器警告。谁能告诉我NSNumber(value) 的问题是什么?
据我了解value as NSNumber 和NSNumber(value) 应该是同一个东西。
【问题讨论】:
标签: swift swift3 nsnumber xcode8 numberformatter