[英]Trouble casting Error from transaction in SKPaymentTransaction (Swift 3)
I am trying to get to the error code in a transaction (Swift 3): 我正在尝试获取事务中的错误代码(Swift 3):
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
if let errorCode = (transaction.error as NSError).code {
//Do something
}
}
}
I am getting the below error. 我收到以下错误。
'Error?'
'错误?' is not convertible to 'NSError';
不能转换为“ NSError”; did you mean to use 'as!'
您是要使用“ as!”吗? to force downcast?`.
强迫沮丧?
Why wont this work? 为什么不做这项工作? I thought Error could cast to NSError in Swift 3.
我以为Error可以在Swift 3中转换为NSError。
Try to cast the Error
object to NSError
then access error code. 尝试将
Error
对象转换为NSError
然后访问错误代码。
if let nsError = error as? NSError {
print(nsError.code)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.