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

Could not cast value of type 'NSError' (0x264bd90) to 'NSString'

因此,当我尝试 运行 这段代码并出现错误时,我遇到了崩溃。我不知道如何正确地做到这一点。

这是我的函数:

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

和我的错误日志:

Error Domain=com.danskebank.mobilepay Code=1001 "Not able to open the MobilePay app" UserInfo={NSLocalizedFailureReason=未安装MobilePay应用程序,NSLocalizedRecoverySuggestion=请安装MobilePay应用程序并重试。,NSLocalizedDescription=无法打开移动支付应用} 无法将类型 'NSError' (0x264bd90) 的值转换为 'NSString' (0x264d6b8)。 (lldb)

看起来打印正常,打印出了错误,但是最后一行我找谁呢

Could not cast value of type 'NSError' (0x264bd90) to 'NSString' (0x264d6b8). (lldb)

我该如何解决?

尝试 localizedDescription 属性 的 Error 对象,像这样:

self.alert(message: Error.localizedDescription)

Error Domain=com.danskebank.mobilepay Code=1001 "Not able to open the MobilePay app" UserInfo={NSLocalizedFailureReason=MobilePay App is not installed, NSLocalizedRecoverySuggestion=Please install MobilePay app and try again., NSLocalizedDescription=Not able to open the MobilePay app} Could not cast value of type 'NSError' (0x264bd90) to 'NSString' (0x264d6b8). (lldb)