问题
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