Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3

℡╲_俬逩灬. 提交于 2019-12-18 09:49:16

问题


Since converting my codebase to swift 3 with Xcode 8 GM, I get this error when trying to conform to the STPAddCardViewControllerDelegate (Stripe SDK). I'm very surprised by this error because even when stubbing those methods automatically with Xcode I encounter the same error. Types seem to match, no idea what's going on.

extension ViewController: STPAddCardViewControllerDelegate {

    func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
    }

    func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: STPErrorBlock) {
    }
}

Generates this error

Type 'ViewController' does not conform to protocol 'STPAddCardViewControllerDelegate'

Protocol requires function 'addCardViewController(_:didCreateToken:completion:)' with type '(STPAddCardViewController, STPToken, STPErrorBlock) -> Void'; do you want to add a stub?

Candidate has non-matching type '(STPAddCardViewController, STPToken, (Error?) -> Void) -> ()'

Here's the definition of the protocol

public protocol STPAddCardViewControllerDelegate : NSObjectProtocol {
    public func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController)
    public func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: Stripe.STPErrorBlock)
}

What am I missing here?


回答1:


After a bit of investigation from @AliSoftware and @bdorfman in the related Stripe SDK issue, it's been found that adding the @escaping attribute to the completion param fixes the issue.

It seems to be a compiler & stubbing issue on swift's end, that is currently tracked here: https://bugs.swift.org/browse/SR-2596.



来源:https://stackoverflow.com/questions/39381210/cannot-conform-to-stpaddcardviewcontrollerdelegate-since-xcode-8-gm-on-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!