gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:03:14 24 4
gpt4 key购买 nike

因此,当我尝试运行此代码并发生错误时,我崩溃了。我不知道如何正确地做。

这是我的功能:

 @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代码= 1001“无法打开MobilePay应用程序” UserInfo = {NSLocalizedFailureReason =未安装MobilePay应用程序,NSLocalizedRecoverySuggestion =请安装MobilePay应用程序,然后重试。,NSLocalizedDescription =无法打开MobilePay应用}
无法将类型'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)

关于swift - 无法将 'NSError'(0x264bd90)类型的值转换为 'NSString',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43761668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com