因此,当我尝试运行此代码并发生错误时,发生崩溃。我无法弄清楚如何正确地做到这一点。无法将类型'NSError'(0x264bd90)的值转换为'NSString'
这里是我的FUNC:
@IBAction func MobilePay(_ sender: Any) {
let payment = MobilePayPayment(orderId: "123456", productPrice: 10.0)
//No need to start a payment if one or more parameters are missing
if (payment != nil) && ((payment?.orderId.characters.count)! > 0) && ((payment?.productPrice)! >= 0) {
MobilePayManager.sharedInstance().beginMobilePayment(with: payment!, error: { (Error) in
print(Error)
self.alert(message: Error as! String)
})
}
}
和我的错误日志:
错误域= com.danskebank.mobilepay代码= 1001 “无法打开MobilePay应用” 的UserInfo = {NSLocalizedFailureReason = MobilePay应用程序未安装,NSLocalizedRecoverySuggestion =请安装MobilePay应用程序,然后重试。,NSLocalizedDescription =无法打开MobilePay应用程序} 无法将类型'NSError'(0x264bd90)的值转换为'NSString'(0x264d6b8)。 (LLDB)
看来版画作品,并打印错误,但谁做我得到的最后一行
无法投类型的值“NSError”(0x264bd90)到“的NSString” (0x264d6b8)。 (lldb)
以及我该如何解决?
调用局部变量'Error'是模糊处理,因为* protocol *具有相同的名称。除此之外:是什么让你认为你可以将错误转换为字符串? 'error.localizedDescription'可能就是你想要的。 –