无法将'NSError'(0x264bd90)类型的值转换为'NSString'

时间:2017-05-03 13:35:21

标签: swift error-handling nsstring nserror

因此,当我尝试运行此代码并发生错误时,我遇到了崩溃。我无法弄清楚如何正确地做到这一点。

这是我的功能:

 @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)
            })
        }
    }

和我的错误记录:

错误Domain = com.danskebank.mobilepay Code = 1001“无法打开MobilePay应用程序”UserInfo = {NSLocalizedFailureReason =未安装MobilePay应用程序,NSLocalizedRecoverySuggestion =请安装MobilePay应用程序并重试。,NSLocalizedDescription =无法打开MobilePay应用程序} 无法将'NSError'(0x264bd90)类型的值转换为'NSString'(0x264d6b8)。 (lldb)

似乎打印工作并且打印出错误,但是我得到了最后一行

  

无法将'NSError'(0x264bd90)类型的值转换为'NSString'   (0x264d6b8)。 (LLDB)

我该如何解决?

1 个答案:

答案 0 :(得分:3)

尝试src="//cdn.example.com...对象的localizedDescription属性,如下所示:

Error
  

错误Domain = com.danskebank.mobilepay Code = 1001“无法打开   MobilePay app“UserInfo = {NSLocalizedFailureReason = MobilePay App不是   安装,NSLocalizedRecoverySuggestion =请安装MobilePay应用程序   然后重试。 NSLocalizedDescription =无法打开MobilePay   app}无法将'NSError'(0x264bd90)类型的值转换为'NSString'   (0x264d6b8)。 (LLDB)