[英]terminating with uncaught exception of type NSException in Swift 5
My code works when my code makes etc: 2 + 2 But my app shut down when my code makes ex: 2+2+ . 我的代码在执行以下代码时可以正常工作: 2 + 2但是,当我的代码进行例如2 + 2 +时,我的应用程序将关闭。
I tried to do - catch code block and many error handling. 我试图做-捕获代码块和许多错误处理。 I can't solve the problem.
我无法解决问题。
let islem: String = screenTextfield.text!
let exp: NSExpression = NSExpression(format: islem)
if let result: Double = exp.expressionValue(with: nil, context: nil) as? Double{
islemLabel.text = String(result)
}
Maybe something like this 也许像这样
var islem: String = screenTextfield.text!
if let number = Int(String(islem.last!)) {
print(number)
}
else {
islem.removeLast()
}
let exp = NSExpression(format: islem)
if let result = exp.expressionValue(with: nil, context: nil) as? NSNumber {
islemLabel.text = String(result.doubleValue)
}
else {
makeAlert(title: "Error", message: "Wrong math type")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.