Trying to add a protocol to a Class signature in swift

和自甴很熟 提交于 2019-12-05 13:30:49

Have you implemented the required methods in your class?

paymentQueue:updatedTransactions: and paymentQueue:updatedDownloads: are required methods and you will get a warning if they are not implemented.

SKPaymentTransactionProtocol has these methods:

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) 
@optional func paymentQueue(queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!)
@optional func paymentQueue(queue: SKPaymentQueue!, restoreCompletedTransactionsFailedWithError error: NSError!)
@optional func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!)
@optional func paymentQueue(queue: SKPaymentQueue!, updatedDownloads downloads: [AnyObject]!)

The first is a required method that your class has to implement in order to conform to the protocol. Add it to your ViewController and the error will disappear.

class ViewController: UIViewController, UITextFieldDelegate, UIAlertViewDelegate,   
SKStoreProductViewControllerDelegate, SKPaymentTransactionObserver{
    func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!){/*...*/}
    /*...*/
}

For swift use this:

public func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { /* */ }

Instead of this:

public func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) { /* */ }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!