【问题标题】:Trouble casting Error from transaction in SKPaymentTransaction (Swift 3)SKPaymentTransaction(Swift 3)中的交易错误转换问题
【发布时间】:2016-09-28 10:55:57
【问题描述】:

我正在尝试获取事务中的错误代码 (Swift 3):

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            if let errorCode = (transaction.error as NSError).code {
             //Do something
            }
        }


}

我收到以下错误。

“错误?”不能转换为“NSError”;你的意思是用'as!'强制沮丧?`。

为什么这不起作用?我认为 Error 可以在 Swift 3 中转换为 NSError。

【问题讨论】:

    标签: ios swift swift3 nserror


    【解决方案1】:

    尝试将Error 对象转换为NSError,然后访问错误代码。

    if let nsError = error as? NSError {
        print(nsError.code)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多