我对转换错误有点困惑。
我将我的项目从 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.0Type(value)
中现在禁止强制转换,但我检查了一下,我绝对没有收到编译器警告。有人可以告诉我有什么问题NSNumber(value)
吗?
据我了解value as NSNumber
,NSNumber(value)
应该是一样的。