In swift 2.1, this purchase function worked. Help remake on swift 3.1

var listOfProducts = [SKProduct]() var productoPurchase = SKProduct() func buyProduct() { print("buy " + productoPurchase.productIdentifier) let pay = SKPayment(product: productoPurchase) SKPaymentQueue.defaultQueue().addTransactionObserver(self) SKPaymentQueue.defaultQueue().addPayment(pay) } 

Xcode swears by strings

 SKPaymentQueue.defaultQueue().addTransactionObserver(self) SKPaymentQueue.defaultQueue().addPayment(pay) 

And offers to fix on

 SKPaymentQueue.default().add(self) SKPaymentQueue.default().add(pay) 

A little searching found the option to fix the second line on

 SKPaymentQueue.default().remove(pay) 

https://codedump.io/share/GYuvWc0s4HMi/1/skpaymentqueuedefaultqueueaddpaymentpayment-crash-when-moving-between-vc-swift-2330

    1 answer 1

    SKPaymentQueue.default().add(self) . . . let payment = SKPayment(product: product) SKPaymentQueue.default().add(payment)

    In general, it is necessary to study this well, if you want to do everything correctly, pay attention to the fact that there are pieces of code marked as ' how not to do (Does not follow best practices ..) 'and' how to do (Follows best practices .. ) '. Your code does not look like the last type.