2016-09-28 57 views
0

我試圖去在一個事務中的錯誤代碼(SWIFT 3):麻煩SKPaymentTransaction從交易鑄造錯誤(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。

回答

1

嘗試將Error對象轉換爲NSError,然後訪問錯誤代碼。

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